From 4188f38ad56d7ba2ea46e94403f305243514f80c Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 15:49:36 +0200 Subject: add pdf and mobi libraries --- inc/poche/WallabagEpub.class.php | 114 ++++++++++++++++++++++++++++++++++++--- inc/poche/global.inc.php | 10 ++++ 2 files changed, 117 insertions(+), 7 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEpub.class.php b/inc/poche/WallabagEpub.class.php index 9c4d3566..14774425 100644 --- a/inc/poche/WallabagEpub.class.php +++ b/inc/poche/WallabagEpub.class.php @@ -8,11 +8,14 @@ * @license http://opensource.org/licenses/MIT see COPYING file */ -class WallabagEpub +class WallabagEBooks { - protected $wallabag; + protected $wallabag; protected $method; protected $value; + protected $entries; + protected $bookTitle; + protected $bookFileName; public function __construct(Poche $wallabag, $method, $value) { @@ -21,10 +24,7 @@ class WallabagEpub $this->value = $value; } - /** - * handle ePub - */ - public function run() + public function prepareData() { switch ($this->method) { case 'id': @@ -62,7 +62,16 @@ class WallabagEpub case 'default': die(_('Uh, there is a problem while generating epub.')); } + } +} +class WallabagEpub extends WallabagEBooks +{ + /** + * handle ePub + */ + public function produceEpub() + { $content_start = "\n" . "\n" @@ -132,4 +141,95 @@ class WallabagEpub $book->finalize(); $zipData = $book->sendBook($bookFileName); } -} \ No newline at end of file +} + +class WallabagMobi extends WallabagEBooks +{ + /** + * Adapted from News2Kindle + * @author Jakub Westfalewski + * + */ + + public function produceMobi() + { + $storage = new Storage('static'); + $this->prepareData(); + foreach ($entries as $i => $item) { + $content = $item['content']; + $images = new Images($storage, $content); + $content = $images->convert(); + $storage->add_content + ( + md5($item['title']), + mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), + $content, + $item['url']], + "" + ); + } + $articles = $storage->get_contents(); + $toc = array(); + $articles_count = count($articles); + + foreach($articles as $article){ + if(array_key_exists($article->website->title, $toc)){ + $toc[$article->website->title]->articles[] = $article; + }else{ + $toc[$article->website->title] = (object)array( + 'articles' => array($article), + 'title' => $article->website->title, + 'streamId' => $article->website->streamId, + 'url' => $article->website->htmlUrl, + ); + } + } + + $mobi = new MOBI(); + $mobi->setData($content); + $mobi->setOptions(array( + 'title' => 'Articles from '.date('Y-m-d'), + 'author' => 'wallabag', + 'subject' => 'Articles from '.date('Y-m-d'), + )); + + $images = array(); + + //prepare images for mobi format + foreach ( $storage->info('images') as $n => $image ) + { + $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); + } + + $mobi->setImages($images); + $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); + + $storage->clean(); + + if ($send) { + $files = glob($storage->get_path(FALSE).'*.mobi'); + $mail = new Send(KINDLEMAIL,MAIL); + foreach ( $files as $file_mobi ) + { + $mail->send( $file_mobi ); + } + // clean cache + foreach ( $files as $file_mobi ) + { + unlink( $file_mobi ); + } + } + } +} + +class WallabagPDF extends WallabagEbooks +{ + public function producePDF() + { + $mpdf = new mPDF('c'); + + $mpdf->WriteHTML($html); + $mpdf->Output(); + exit; + } +} \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index b8c487e3..e3687eb2 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -41,6 +41,16 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php'; require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; +# mobi library +require_once INCLUDES . '/3rdparty/libraries/send2kindle/send.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/images.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/storage.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/utils.php'; + +# pdf library +require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; + # system configuration; database credentials et caetera require_once INCLUDES . '/poche/config.inc.php'; require_once INCLUDES . '/poche/config.inc.default.php'; -- cgit v1.2.3 From 15317991f3ff456e6e215947402a0dcfd951e0df Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 15:53:23 +0200 Subject: from epub to all kind of ebooks --- inc/poche/WallabagEBooks.class.php | 235 +++++++++++++++++++++++++++++++++++++ inc/poche/WallabagEpub.class.php | 235 ------------------------------------- inc/poche/global.inc.php | 2 +- 3 files changed, 236 insertions(+), 236 deletions(-) create mode 100644 inc/poche/WallabagEBooks.class.php delete mode 100644 inc/poche/WallabagEpub.class.php (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php new file mode 100644 index 00000000..14774425 --- /dev/null +++ b/inc/poche/WallabagEBooks.class.php @@ -0,0 +1,235 @@ + + * @copyright 2013 + * @license http://opensource.org/licenses/MIT see COPYING file + */ + +class WallabagEBooks +{ + protected $wallabag; + protected $method; + protected $value; + protected $entries; + protected $bookTitle; + protected $bookFileName; + + public function __construct(Poche $wallabag, $method, $value) + { + $this->wallabag = $wallabag; + $this->method = $method; + $this->value = $value; + } + + public function prepareData() + { + switch ($this->method) { + case 'id': + $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); + $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); + $entries = array($entry); + $bookTitle = $entry['title']; + $bookFileName = substr($bookTitle, 0, 200); + break; + case 'all': + $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); + $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system + $bookFileName = _('Allarticles') . date(_('dmY')); + break; + case 'tag': + $tag = filter_var($this->value, FILTER_SANITIZE_STRING); + $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->user->getId(), $tag); + $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. + $entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); + $bookTitle = sprintf(_('Articles tagged %s'), $tag); + $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); + break; + case 'category': + $category = filter_var($this->value, FILTER_SANITIZE_STRING); + $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); + $bookTitle = sprintf(_('All articles in category %s'), $category); + $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); + break; + case 'search': + $search = filter_var($this->value, FILTER_SANITIZE_STRING); + $entries = $this->store->search($search, $this->wallabag->user->getId()); + $bookTitle = sprintf(_('All articles for search %s'), $search); + $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); + break; + case 'default': + die(_('Uh, there is a problem while generating epub.')); + } + } +} + +class WallabagEpub extends WallabagEBooks +{ + /** + * handle ePub + */ + public function produceEpub() + { + $content_start = + "\n" + . "\n" + . "" + . "\n" + . "wallabag articles book\n" + . "\n" + . "\n"; + + $bookEnd = "\n\n"; + + $log = new Logger("wallabag", TRUE); + $fileDir = CACHE; + + $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE); + $log->logLine("new EPub()"); + $log->logLine("EPub class version: " . EPub::VERSION); + $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); + $log->logLine("Zip version: " . Zip::VERSION); + $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); + $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); + + $book->setTitle($bookTitle); + $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. + //$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. + $book->setDescription(_("Some articles saved on my wallabag")); + $book->setAuthor("wallabag", "wallabag"); + $book->setPublisher("wallabag", "wallabag"); // I hope this is a non existant address :) + $book->setDate(time()); // Strictly not needed as the book date defaults to time(). + //$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. + $book->setSourceURL("http://$_SERVER[HTTP_HOST]"); + + $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); + $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag"); + + $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"; + + $log->logLine("Add Cover"); + + $fullTitle = "

" . $bookTitle . "

\n"; + + $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); + + $cover = $content_start . '

' . _('Produced by wallabag with PHPePub') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

' . $bookEnd; + + //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE); + $book->addChapter("Notices", "Cover2.html", $cover); + + $book->buildTOC(); + + foreach ($entries as $entry) { //set tags as subjects + $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); + foreach ($tags as $tag) { + $book->setSubject($tag['value']); + } + + $log->logLine("Set up parameters"); + + $chapter = $content_start . $entry['content'] . $bookEnd; + $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); + $log->logLine("Added chapter " . $entry['title']); + } + + if (DEBUG_POCHE) { + $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation + } + $book->finalize(); + $zipData = $book->sendBook($bookFileName); + } +} + +class WallabagMobi extends WallabagEBooks +{ + /** + * Adapted from News2Kindle + * @author Jakub Westfalewski + * + */ + + public function produceMobi() + { + $storage = new Storage('static'); + $this->prepareData(); + foreach ($entries as $i => $item) { + $content = $item['content']; + $images = new Images($storage, $content); + $content = $images->convert(); + $storage->add_content + ( + md5($item['title']), + mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), + $content, + $item['url']], + "" + ); + } + $articles = $storage->get_contents(); + $toc = array(); + $articles_count = count($articles); + + foreach($articles as $article){ + if(array_key_exists($article->website->title, $toc)){ + $toc[$article->website->title]->articles[] = $article; + }else{ + $toc[$article->website->title] = (object)array( + 'articles' => array($article), + 'title' => $article->website->title, + 'streamId' => $article->website->streamId, + 'url' => $article->website->htmlUrl, + ); + } + } + + $mobi = new MOBI(); + $mobi->setData($content); + $mobi->setOptions(array( + 'title' => 'Articles from '.date('Y-m-d'), + 'author' => 'wallabag', + 'subject' => 'Articles from '.date('Y-m-d'), + )); + + $images = array(); + + //prepare images for mobi format + foreach ( $storage->info('images') as $n => $image ) + { + $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); + } + + $mobi->setImages($images); + $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); + + $storage->clean(); + + if ($send) { + $files = glob($storage->get_path(FALSE).'*.mobi'); + $mail = new Send(KINDLEMAIL,MAIL); + foreach ( $files as $file_mobi ) + { + $mail->send( $file_mobi ); + } + // clean cache + foreach ( $files as $file_mobi ) + { + unlink( $file_mobi ); + } + } + } +} + +class WallabagPDF extends WallabagEbooks +{ + public function producePDF() + { + $mpdf = new mPDF('c'); + + $mpdf->WriteHTML($html); + $mpdf->Output(); + exit; + } +} \ No newline at end of file diff --git a/inc/poche/WallabagEpub.class.php b/inc/poche/WallabagEpub.class.php deleted file mode 100644 index 14774425..00000000 --- a/inc/poche/WallabagEpub.class.php +++ /dev/null @@ -1,235 +0,0 @@ - - * @copyright 2013 - * @license http://opensource.org/licenses/MIT see COPYING file - */ - -class WallabagEBooks -{ - protected $wallabag; - protected $method; - protected $value; - protected $entries; - protected $bookTitle; - protected $bookFileName; - - public function __construct(Poche $wallabag, $method, $value) - { - $this->wallabag = $wallabag; - $this->method = $method; - $this->value = $value; - } - - public function prepareData() - { - switch ($this->method) { - case 'id': - $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); - $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); - $entries = array($entry); - $bookTitle = $entry['title']; - $bookFileName = substr($bookTitle, 0, 200); - break; - case 'all': - $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); - $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system - $bookFileName = _('Allarticles') . date(_('dmY')); - break; - case 'tag': - $tag = filter_var($this->value, FILTER_SANITIZE_STRING); - $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->user->getId(), $tag); - $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. - $entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('Articles tagged %s'), $tag); - $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); - break; - case 'category': - $category = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('All articles in category %s'), $category); - $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); - break; - case 'search': - $search = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->store->search($search, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('All articles for search %s'), $search); - $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); - break; - case 'default': - die(_('Uh, there is a problem while generating epub.')); - } - } -} - -class WallabagEpub extends WallabagEBooks -{ - /** - * handle ePub - */ - public function produceEpub() - { - $content_start = - "\n" - . "\n" - . "" - . "\n" - . "wallabag articles book\n" - . "\n" - . "\n"; - - $bookEnd = "\n\n"; - - $log = new Logger("wallabag", TRUE); - $fileDir = CACHE; - - $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE); - $log->logLine("new EPub()"); - $log->logLine("EPub class version: " . EPub::VERSION); - $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); - $log->logLine("Zip version: " . Zip::VERSION); - $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); - $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); - - $book->setTitle($bookTitle); - $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. - //$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. - $book->setDescription(_("Some articles saved on my wallabag")); - $book->setAuthor("wallabag", "wallabag"); - $book->setPublisher("wallabag", "wallabag"); // I hope this is a non existant address :) - $book->setDate(time()); // Strictly not needed as the book date defaults to time(). - //$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. - $book->setSourceURL("http://$_SERVER[HTTP_HOST]"); - - $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); - $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag"); - - $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"; - - $log->logLine("Add Cover"); - - $fullTitle = "

" . $bookTitle . "

\n"; - - $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); - - $cover = $content_start . '

' . _('Produced by wallabag with PHPePub') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

' . $bookEnd; - - //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE); - $book->addChapter("Notices", "Cover2.html", $cover); - - $book->buildTOC(); - - foreach ($entries as $entry) { //set tags as subjects - $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); - foreach ($tags as $tag) { - $book->setSubject($tag['value']); - } - - $log->logLine("Set up parameters"); - - $chapter = $content_start . $entry['content'] . $bookEnd; - $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); - $log->logLine("Added chapter " . $entry['title']); - } - - if (DEBUG_POCHE) { - $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation - } - $book->finalize(); - $zipData = $book->sendBook($bookFileName); - } -} - -class WallabagMobi extends WallabagEBooks -{ - /** - * Adapted from News2Kindle - * @author Jakub Westfalewski - * - */ - - public function produceMobi() - { - $storage = new Storage('static'); - $this->prepareData(); - foreach ($entries as $i => $item) { - $content = $item['content']; - $images = new Images($storage, $content); - $content = $images->convert(); - $storage->add_content - ( - md5($item['title']), - mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), - $content, - $item['url']], - "" - ); - } - $articles = $storage->get_contents(); - $toc = array(); - $articles_count = count($articles); - - foreach($articles as $article){ - if(array_key_exists($article->website->title, $toc)){ - $toc[$article->website->title]->articles[] = $article; - }else{ - $toc[$article->website->title] = (object)array( - 'articles' => array($article), - 'title' => $article->website->title, - 'streamId' => $article->website->streamId, - 'url' => $article->website->htmlUrl, - ); - } - } - - $mobi = new MOBI(); - $mobi->setData($content); - $mobi->setOptions(array( - 'title' => 'Articles from '.date('Y-m-d'), - 'author' => 'wallabag', - 'subject' => 'Articles from '.date('Y-m-d'), - )); - - $images = array(); - - //prepare images for mobi format - foreach ( $storage->info('images') as $n => $image ) - { - $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); - } - - $mobi->setImages($images); - $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); - - $storage->clean(); - - if ($send) { - $files = glob($storage->get_path(FALSE).'*.mobi'); - $mail = new Send(KINDLEMAIL,MAIL); - foreach ( $files as $file_mobi ) - { - $mail->send( $file_mobi ); - } - // clean cache - foreach ( $files as $file_mobi ) - { - unlink( $file_mobi ); - } - } - } -} - -class WallabagPDF extends WallabagEbooks -{ - public function producePDF() - { - $mpdf = new mPDF('c'); - - $mpdf->WriteHTML($html); - $mpdf->Output(); - exit; - } -} \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index e3687eb2..1542fbfa 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -22,7 +22,7 @@ require_once ROOT . '/vendor/autoload.php'; require_once INCLUDES . '/poche/Template.class.php'; require_once INCLUDES . '/poche/Language.class.php'; require_once INCLUDES . '/poche/Routing.class.php'; -require_once INCLUDES . '/poche/WallabagEpub.class.php'; +require_once INCLUDES . '/poche/WallabagEBooks.class.php'; require_once INCLUDES . '/poche/Poche.class.php'; require_once INCLUDES . '/poche/Database.class.php'; -- cgit v1.2.3 From c70bfefc68fcc96b1ce57845e5b2942a596239ec Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 15:59:08 +0200 Subject: add mobi and pdf to routing --- inc/poche/Routing.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 2db57d12..e01d8129 100644 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -112,7 +112,13 @@ class Routing $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); - $epub->run(); + $epub->produceEpub(); + } elseif (isset($_GET['mobi'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->produceMobi(); + } elseif (isset($_GET['pdf'])) { + $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); + $pdf->producePDF(); } elseif (isset($_GET['import'])) { $import = $this->wallabag->import(); $tplVars = array_merge($this->vars, $import); -- cgit v1.2.3 From fb9df0c269f36703909b8b259abbdbed29881ecd Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 21:56:04 +0200 Subject: use directly MOBIClass --- inc/poche/Routing.class.php | 3 + inc/poche/WallabagEBooks.class.php | 166 +++++++++++++++++-------------------- inc/poche/global.inc.php | 6 +- 3 files changed, 80 insertions(+), 95 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index e01d8129..83eabf19 100644 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -112,12 +112,15 @@ class Routing $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); + $epub->prepareData(); $epub->produceEpub(); } elseif (isset($_GET['mobi'])) { $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); $mobi->produceMobi(); } elseif (isset($_GET['pdf'])) { $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); + $pdf->prepareData(); $pdf->producePDF(); } elseif (isset($_GET['import'])) { $import = $this->wallabag->import(); diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 14774425..deaf57e2 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -30,34 +30,35 @@ class WallabagEBooks case 'id': $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); - $entries = array($entry); - $bookTitle = $entry['title']; - $bookFileName = substr($bookTitle, 0, 200); + $this->entries = array($entry); + $this->bookTitle = $entry['title']; + $this->bookFileName = substr($this->bookTitle, 0, 200); break; case 'all': - $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); - $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system - $bookFileName = _('Allarticles') . date(_('dmY')); + $this->entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system + $this->bookFileName = _('Allarticles') . date(_('dmY')); break; case 'tag': $tag = filter_var($this->value, FILTER_SANITIZE_STRING); $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->user->getId(), $tag); $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. - $entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('Articles tagged %s'), $tag); - $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); + $this->entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('Articles tagged %s'), $tag); + $this->bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); break; case 'category': $category = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('All articles in category %s'), $category); - $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); + $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('All articles in category %s'), $category); + $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); break; case 'search': $search = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->store->search($search, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('All articles for search %s'), $search); - $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); + Tools::logm($search); + $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('All articles for search %s'), $search); + $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); break; case 'default': die(_('Uh, there is a problem while generating epub.')); @@ -94,7 +95,7 @@ class WallabagEpub extends WallabagEBooks $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); - $book->setTitle($bookTitle); + $book->setTitle($this->bookTitle); $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. //$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. $book->setDescription(_("Some articles saved on my wallabag")); @@ -111,7 +112,7 @@ class WallabagEpub extends WallabagEBooks $log->logLine("Add Cover"); - $fullTitle = "

" . $bookTitle . "

\n"; + $fullTitle = "

" . $this->bookTitle . "

\n"; $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); @@ -122,7 +123,7 @@ class WallabagEpub extends WallabagEBooks $book->buildTOC(); - foreach ($entries as $entry) { //set tags as subjects + foreach ($this->entries as $entry) { //set tags as subjects $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); foreach ($tags as $tag) { $book->setSubject($tag['value']); @@ -139,97 +140,82 @@ class WallabagEpub extends WallabagEBooks $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation } $book->finalize(); - $zipData = $book->sendBook($bookFileName); + $zipData = $book->sendBook($this->bookFileName); } } class WallabagMobi extends WallabagEBooks { /** - * Adapted from News2Kindle - * @author Jakub Westfalewski - * + * MOBI Class + * @author Sander Kromwijk */ - public function produceMobi() + public function produceMobi($send = FALSE) { - $storage = new Storage('static'); - $this->prepareData(); - foreach ($entries as $i => $item) { - $content = $item['content']; - $images = new Images($storage, $content); - $content = $images->convert(); - $storage->add_content - ( - md5($item['title']), - mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), - $content, - $item['url']], - "" - ); - } - $articles = $storage->get_contents(); - $toc = array(); - $articles_count = count($articles); - - foreach($articles as $article){ - if(array_key_exists($article->website->title, $toc)){ - $toc[$article->website->title]->articles[] = $article; - }else{ - $toc[$article->website->title] = (object)array( - 'articles' => array($article), - 'title' => $article->website->title, - 'streamId' => $article->website->streamId, - 'url' => $article->website->htmlUrl, - ); - } - } - - $mobi = new MOBI(); - $mobi->setData($content); - $mobi->setOptions(array( - 'title' => 'Articles from '.date('Y-m-d'), - 'author' => 'wallabag', - 'subject' => 'Articles from '.date('Y-m-d'), - )); - $images = array(); - - //prepare images for mobi format - foreach ( $storage->info('images') as $n => $image ) - { - $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); + # Good try + $mobi = new MOBI(); + + $content = new MOBIFile(); + + $content->set("title", $this->bookTitle); + $content->set("author", "wallabag"); + + # introduction + //$content->appendChapterTitle("Cover"); + $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); + $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); + $content->appendPageBreak(); + + foreach ($this->entries as $item) { + $content->appendChapterTitle($item['title']); + $content->appendParagraph($item['content']); + $content->appendPageBreak(); } + $mobi->setContentProvider($content); - $mobi->setImages($images); - $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); - - $storage->clean(); - - if ($send) { - $files = glob($storage->get_path(FALSE).'*.mobi'); - $mail = new Send(KINDLEMAIL,MAIL); - foreach ( $files as $file_mobi ) - { - $mail->send( $file_mobi ); - } - // clean cache - foreach ( $files as $file_mobi ) - { - unlink( $file_mobi ); - } - } - } + $mobi->download($this->bookFileName.".mobi"); + } } class WallabagPDF extends WallabagEbooks { public function producePDF() { + //$this->prepareData(); $mpdf = new mPDF('c'); - $mpdf->WriteHTML($html); - $mpdf->Output(); - exit; + # intro + + $html = '

' . $this->bookTitle . '

'; + + foreach ($this->entries as $item) { + $html .= '

' . $item['title'] . '

'; + $html .= ''; + $html .= $item['content']; + } + + //$mpdf->h2toc = array('H1'=>0); + + # headers + $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); + $mpdf->SetFooter('{PAGENO}'); + + $mpdf->WriteHTML($html); + + # remove characters that make mpdf bug + $char_in = array('/', '.', ',', ':', '|'); + $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); + + $mpdf->Output('cache/' . $pdfExportName); + + header('Content-Disposition: attachment; filename="' . $pdfExportName . '"'); + + header('Content-Transfer-Encoding: base64'); + header('Content-Type: application/pdf'); + echo file_get_contents('cache/' . $pdfExportName); + + //exit; } } \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 1542fbfa..182f721d 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -42,11 +42,7 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; # mobi library -require_once INCLUDES . '/3rdparty/libraries/send2kindle/send.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/images.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/storage.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/utils.php'; +require_once INCLUDES . '/3rdparty/libraries/MOBIClass/MOBI.php'; # pdf library require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; -- cgit v1.2.3 From deab6280d3cbe3f8d001ff5214d36399653e3027 Mon Sep 17 00:00:00 2001 From: tcit Date: Fri, 25 Jul 2014 00:33:19 +0200 Subject: mobi (not tested on actual device) and pdf working --- inc/poche/WallabagEBooks.class.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index deaf57e2..2b18b718 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -36,7 +36,7 @@ class WallabagEBooks break; case 'all': $this->entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); - $this->bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system + $this->bookTitle = sprintf(_('All my articles on %s'), date(_('d.m.y'))); #translatable because each country has it's own date format system $this->bookFileName = _('Allarticles') . date(_('dmY')); break; case 'tag': @@ -154,17 +154,17 @@ class WallabagMobi extends WallabagEBooks public function produceMobi($send = FALSE) { - # Good try $mobi = new MOBI(); $content = new MOBIFile(); $content->set("title", $this->bookTitle); $content->set("author", "wallabag"); + $content->set("subject", $this->bookTitle); # introduction //$content->appendChapterTitle("Cover"); - $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); + $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); $content->appendPageBreak(); @@ -183,20 +183,25 @@ class WallabagPDF extends WallabagEbooks { public function producePDF() { - //$this->prepareData(); $mpdf = new mPDF('c'); # intro - $html = '

' . $this->bookTitle . '

'; + $html = '

' . $this->bookTitle . '

+

' . _('Produced by wallabag with mPDF') . '

+

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

+
'; + $html .= ''; + $i = 1; foreach ($this->entries as $item) { - $html .= '

' . $item['title'] . '

'; + $html .= '

' . $item['title'] . '

'; $html .= ''; $html .= $item['content']; + $html .= ''; + $i = $i+1; } - //$mpdf->h2toc = array('H1'=>0); # headers $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); @@ -207,6 +212,13 @@ class WallabagPDF extends WallabagEbooks # remove characters that make mpdf bug $char_in = array('/', '.', ',', ':', '|'); $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); + + # index + $html = '

Index

+ + '; + + $mpdf->WriteHTML($html); $mpdf->Output('cache/' . $pdfExportName); -- cgit v1.2.3 From dc59f164a94ce2ab9e3165aa0090acff8a352493 Mon Sep 17 00:00:00 2001 From: tcit Date: Fri, 25 Jul 2014 01:33:31 +0200 Subject: send2kindle --- inc/poche/Routing.class.php | 4 +++ inc/poche/WallabagEBooks.class.php | 59 +++++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 83eabf19..ec33432c 100644 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -118,6 +118,10 @@ class Routing $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); $mobi->prepareData(); $mobi->produceMobi(); + } elseif (isset($_GET['send2kindle'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); + $mobi->produceMobi(TRUE); } elseif (isset($_GET['pdf'])) { $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); $pdf->prepareData(); diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 2b18b718..a12befa8 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -151,19 +151,21 @@ class WallabagMobi extends WallabagEBooks * @author Sander Kromwijk */ - public function produceMobi($send = FALSE) + private $_kindle_email; + + public function produceMobi($sendByMail = FALSE) { $mobi = new MOBI(); - $content = new MOBIFile(); + + $messages = new Messages(); // for later $content->set("title", $this->bookTitle); $content->set("author", "wallabag"); $content->set("subject", $this->bookTitle); # introduction - //$content->appendChapterTitle("Cover"); $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); $content->appendPageBreak(); @@ -175,7 +177,56 @@ class WallabagMobi extends WallabagEBooks } $mobi->setContentProvider($content); - $mobi->download($this->bookFileName.".mobi"); + if (!$sendByMail) { + // we offer file to download + $mobi->download($this->bookFileName.'.mobi'); + } + else { + // we send file to kindle + + $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) + $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.mobi')); + + $file = 'cache/' . $mobiExportName; + $mobi->save($file); + + $file_size = filesize($file); + $filename = basename($file); + $handle = fopen($file, "r"); + $content = fread($handle, $file_size); + fclose($handle); + $content = chunk_split(base64_encode($content)); + + $uid = md5(uniqid(time())); + + //generate header for mail + $header = "From: wallabag <". $this->wallabag->user->email .">\r\n"; + $header .= "MIME-Version: 1.0\r\n"; + $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; + $header .= "This is a multi-part message in MIME format.\r\n"; + $header .= "--".$uid."\r\n"; + $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; + $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; + $header .= "send via wallabag\r\n\r\n"; + $header .= "--".$uid."\r\n"; + $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n"; + $header .= "Content-Transfer-Encoding: base64\r\n"; + $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; + $header .= $content."\r\n\r\n"; + $header .= "--".$uid."--"; + + # trying to get the kindle email adress + if ($this->wallabag->user->getConfigValue('kindleemail')) + { + #do a try...exeption here + mail( $this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); + $messages->add('s', _('The email has been sent to your kindle !')); + } + else + { + $messages->add('e', _('You didn\'t set your kindle\'s email adress !')); + } + } } } -- cgit v1.2.3 From d49446ff98044bdaf19f06d72c94d513cbbabcec Mon Sep 17 00:00:00 2001 From: tcit Date: Fri, 25 Jul 2014 01:38:28 +0200 Subject: bug with extension in the filename --- inc/poche/WallabagEBooks.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index a12befa8..5f42308e 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -185,7 +185,7 @@ class WallabagMobi extends WallabagEBooks // we send file to kindle $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) - $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.mobi')); + $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName)) . '.mobi'; $file = 'cache/' . $mobiExportName; $mobi->save($file); -- cgit v1.2.3 From f8c37985224313533111e5b1d78b5a20eeff8b04 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 26 Jul 2014 11:52:43 +0200 Subject: little better --- inc/poche/WallabagEBooks.class.php | 76 ++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 23 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 5f42308e..906a2247 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -16,6 +16,7 @@ class WallabagEBooks protected $entries; protected $bookTitle; protected $bookFileName; + protected $author = 'wallabag'; public function __construct(Poche $wallabag, $method, $value) { @@ -33,11 +34,14 @@ class WallabagEBooks $this->entries = array($entry); $this->bookTitle = $entry['title']; $this->bookFileName = substr($this->bookTitle, 0, 200); + $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) + Tools::logm('Producing ebook from article ' . $this->bookTitle); break; case 'all': $this->entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); $this->bookTitle = sprintf(_('All my articles on %s'), date(_('d.m.y'))); #translatable because each country has it's own date format system $this->bookFileName = _('Allarticles') . date(_('dmY')); + Tools::logm('Producing ebook from all articles'); break; case 'tag': $tag = filter_var($this->value, FILTER_SANITIZE_STRING); @@ -46,12 +50,14 @@ class WallabagEBooks $this->entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); $this->bookTitle = sprintf(_('Articles tagged %s'), $tag); $this->bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); + Tools::logm('Producing ebook from tag ' . $tag); break; case 'category': $category = filter_var($this->value, FILTER_SANITIZE_STRING); $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); $this->bookTitle = sprintf(_('All articles in category %s'), $category); $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); + Tools::logm('Producing ebook from category ' . $category); break; case 'search': $search = filter_var($this->value, FILTER_SANITIZE_STRING); @@ -59,9 +65,10 @@ class WallabagEBooks $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId()); $this->bookTitle = sprintf(_('All articles for search %s'), $search); $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); + Tools::logm('Producing ebook from search ' . $search); break; case 'default': - die(_('Uh, there is a problem while generating epub.')); + die(_('Uh, there is a problem while generating eBook.')); } } } @@ -73,12 +80,13 @@ class WallabagEpub extends WallabagEBooks */ public function produceEpub() { + Tools::logm('Starting to produce ePub 3 file'); $content_start = "\n" . "\n" . "" . "\n" - . "wallabag articles book\n" + . "" . _("wallabag articles book") . "\n" . "\n" . "\n"; @@ -95,11 +103,13 @@ class WallabagEpub extends WallabagEBooks $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); + Tools::logm('Filling metadata for ePub...'); + $book->setTitle($this->bookTitle); $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. //$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. $book->setDescription(_("Some articles saved on my wallabag")); - $book->setAuthor("wallabag", "wallabag"); + $book->setAuthor($this->author,$this->author); $book->setPublisher("wallabag", "wallabag"); // I hope this is a non existant address :) $book->setDate(time()); // Strictly not needed as the book date defaults to time(). //$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. @@ -123,6 +133,8 @@ class WallabagEpub extends WallabagEBooks $book->buildTOC(); + Tools::logm('Adding actual content...'); + foreach ($this->entries as $entry) { //set tags as subjects $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); foreach ($tags as $tag) { @@ -138,9 +150,11 @@ class WallabagEpub extends WallabagEBooks if (DEBUG_POCHE) { $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation + Tools::logm('Production log available in produced file'); } $book->finalize(); $zipData = $book->sendBook($this->bookFileName); + Tools::logm('Ebook produced'); } } @@ -151,18 +165,19 @@ class WallabagMobi extends WallabagEBooks * @author Sander Kromwijk */ - private $_kindle_email; - public function produceMobi($sendByMail = FALSE) { + Tools::logm('Starting to produce Mobi file'); $mobi = new MOBI(); $content = new MOBIFile(); $messages = new Messages(); // for later - + + Tools::logm('Filling metadata for Mobi...'); + $content->set("title", $this->bookTitle); - $content->set("author", "wallabag"); + $content->set("author", $this->author); $content->set("subject", $this->bookTitle); # introduction @@ -170,6 +185,8 @@ class WallabagMobi extends WallabagEBooks $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); $content->appendPageBreak(); + Tools::logm('Adding actual content...'); + foreach ($this->entries as $item) { $content->appendChapterTitle($item['title']); $content->appendParagraph($item['content']); @@ -180,10 +197,19 @@ class WallabagMobi extends WallabagEBooks if (!$sendByMail) { // we offer file to download $mobi->download($this->bookFileName.'.mobi'); + Tools::logm('Mobi file produced'); } else { // we send file to kindle + Tools::logm('Preparing to send file by email'); + + $error = FALSE; + # testing Mail function + if (!function_exists('mail')) { + $error = _('Mail function is unavailable'); + } + $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName)) . '.mobi'; @@ -216,15 +242,17 @@ class WallabagMobi extends WallabagEBooks $header .= "--".$uid."--"; # trying to get the kindle email adress - if ($this->wallabag->user->getConfigValue('kindleemail')) + if (!$this->wallabag->user->getConfigValue('kindleemail')) { - #do a try...exeption here - mail( $this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); - $messages->add('s', _('The email has been sent to your kindle !')); + $error = _('You didn\'t set your kindle\'s email adress !'); } - else - { - $messages->add('e', _('You didn\'t set your kindle\'s email adress !')); + if (!$error) { + mail($this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); + $messages->add('s', _('The email has been sent to your kindle !')); + Tools::logm('Email sent'); + } else { + $messages->add('e', $error); + Tools::logm($error); } } } @@ -236,8 +264,15 @@ class WallabagPDF extends WallabagEbooks { $mpdf = new mPDF('c'); - # intro + Tools::logm('Starting to produce PDF file'); + Tools::logm('Filling metadata for PDF...'); + + # headers + $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); + $mpdf->SetFooter('{PAGENO}'); + + # intro $html = '

' . $this->bookTitle . '

' . _('Produced by wallabag with mPDF') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

@@ -245,6 +280,7 @@ class WallabagPDF extends WallabagEbooks $html .= ''; $i = 1; + Tools::logm('Adding actual content...'); foreach ($this->entries as $item) { $html .= '

' . $item['title'] . '

'; $html .= ''; @@ -252,17 +288,12 @@ class WallabagPDF extends WallabagEbooks $html .= ''; $i = $i+1; } - - - # headers - $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); - $mpdf->SetFooter('{PAGENO}'); $mpdf->WriteHTML($html); # remove characters that make mpdf bug $char_in = array('/', '.', ',', ':', '|'); - $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); + $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); # maybe someone can make a proper regex of this ? # index $html = '

Index

@@ -278,7 +309,6 @@ class WallabagPDF extends WallabagEbooks header('Content-Transfer-Encoding: base64'); header('Content-Type: application/pdf'); echo file_get_contents('cache/' . $pdfExportName); - - //exit; + Tools::logm('PDF file produced'); } } \ No newline at end of file -- cgit v1.2.3 From ab86a5124ae4a23cc37dc78ccfbd73089b3248d8 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 26 Jul 2014 13:04:12 +0200 Subject: more translations --- inc/poche/WallabagEBooks.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 906a2247..80aa7e43 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -55,7 +55,7 @@ class WallabagEBooks case 'category': $category = filter_var($this->value, FILTER_SANITIZE_STRING); $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); - $this->bookTitle = sprintf(_('All articles in category %s'), $category); + $this->bookTitle = sprintf(_('Articles in category %s'), $category); $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); Tools::logm('Producing ebook from category ' . $category); break; @@ -63,7 +63,7 @@ class WallabagEBooks $search = filter_var($this->value, FILTER_SANITIZE_STRING); Tools::logm($search); $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId()); - $this->bookTitle = sprintf(_('All articles for search %s'), $search); + $this->bookTitle = sprintf(_('Articles for search %s'), $search); $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); Tools::logm('Producing ebook from search ' . $search); break; @@ -207,7 +207,7 @@ class WallabagMobi extends WallabagEBooks $error = FALSE; # testing Mail function if (!function_exists('mail')) { - $error = _('Mail function is unavailable'); + $error = _("Mail function is disabled. You can't send emails from your server"); } $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) @@ -244,7 +244,7 @@ class WallabagMobi extends WallabagEBooks # trying to get the kindle email adress if (!$this->wallabag->user->getConfigValue('kindleemail')) { - $error = _('You didn\'t set your kindle\'s email adress !'); + $error = _("You didn't set your kindle's email adress !"); } if (!$error) { mail($this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); -- cgit v1.2.3 From 824f8c45edb20e27221e92805b0090f1768a2756 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:34:17 +0200 Subject: changed mpdf with tcpdf --- inc/poche/WallabagEBooks.class.php | 56 ++++++++++++++++---------------------- inc/poche/global.inc.php | 3 +- 2 files changed, 26 insertions(+), 33 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 80aa7e43..d77fe0d8 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -262,53 +262,45 @@ class WallabagPDF extends WallabagEbooks { public function producePDF() { - $mpdf = new mPDF('c'); Tools::logm('Starting to produce PDF file'); - Tools::logm('Filling metadata for PDF...'); - - # headers - $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); - $mpdf->SetFooter('{PAGENO}'); + $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); - # intro - $html = '

' . $this->bookTitle . '

-

' . _('Produced by wallabag with mPDF') . '

+ Tools::logm('Filling metadata for PDF...'); + $pdf->SetCreator(PDF_CREATOR); + $pdf->SetAuthor(''); + $pdf->SetTitle($this->bookTitle); + $pdf->SetSubject('TCPDF Tutorial'); + $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); + + Tools::logm('Adding introduction...'); + $pdf->AddPage(); + $intro = '

' . $this->bookTitle . '

+

' . _('Produced by wallabag with tcpdf') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'; - $html .= ''; - $i = 1; + + $pdf->writeHTMLCell(0, 0, '', '', $intro, 0, 1, 0, true, '', true); + + $i = 1; Tools::logm('Adding actual content...'); foreach ($this->entries as $item) { - $html .= '

' . $item['title'] . '

'; - $html .= ''; + $pdf->AddPage(); + $html = '

' . $item['title'] . '

'; $html .= $item['content']; - $html .= ''; + $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $i = $i+1; } - - $mpdf->WriteHTML($html); - # remove characters that make mpdf bug - $char_in = array('/', '.', ',', ':', '|'); - $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); # maybe someone can make a proper regex of this ? + // set image scale factor + $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); - # index - $html = '

Index

- - '; + + - $mpdf->WriteHTML($html); - - $mpdf->Output('cache/' . $pdfExportName); - - header('Content-Disposition: attachment; filename="' . $pdfExportName . '"'); + $pdf->Output($this->bookFileName, 'I'); - header('Content-Transfer-Encoding: base64'); - header('Content-Type: application/pdf'); - echo file_get_contents('cache/' . $pdfExportName); - Tools::logm('PDF file produced'); } } \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 182f721d..728528f8 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -45,7 +45,8 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; require_once INCLUDES . '/3rdparty/libraries/MOBIClass/MOBI.php'; # pdf library -require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; +#require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; +require_once INCLUDES . '/3rdparty/libraries/tcpdf/tcpdf.php'; # system configuration; database credentials et caetera require_once INCLUDES . '/poche/config.inc.php'; -- cgit v1.2.3 From a1b31d93b69c78db0ebc0635b619b02ee7392957 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:42:37 +0200 Subject: get up to date --- inc/poche/Routing.class.php | 92 ++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 52 deletions(-) mode change 100644 => 100755 inc/poche/Routing.class.php (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php old mode 100644 new mode 100755 index ec33432c..0b373058 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -98,62 +98,50 @@ class Routing private function _launchAction() { if (isset($_GET['login'])) { - // hello you - $this->wallabag->login($this->referer); - } elseif (isset($_GET['logout'])) { - // see you soon ! - $this->wallabag->logout(); - } elseif (isset($_GET['config'])) { - // update password - $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); - } elseif (isset($_GET['newuser'])) { - $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); - } elseif (isset($_GET['deluser'])) { - $this->wallabag->deleteUser($_POST['password4deletinguser']); - } elseif (isset($_GET['epub'])) { - $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); - $epub->prepareData(); - $epub->produceEpub(); - } elseif (isset($_GET['mobi'])) { - $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); - $mobi->prepareData(); - $mobi->produceMobi(); - } elseif (isset($_GET['send2kindle'])) { - $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); - $mobi->prepareData(); - $mobi->produceMobi(TRUE); - } elseif (isset($_GET['pdf'])) { - $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); - $pdf->prepareData(); - $pdf->producePDF(); - } elseif (isset($_GET['import'])) { - $import = $this->wallabag->import(); - $tplVars = array_merge($this->vars, $import); - } elseif (isset($_GET['download'])) { - Tools::downloadDb(); - } elseif (isset($_GET['empty-cache'])) { - Tools::emptyCache(); - } elseif (isset($_GET['export'])) { - $this->wallabag->export(); - } elseif (isset($_GET['updatetheme'])) { - $this->wallabag->tpl->updateTheme($_POST['theme']); - } elseif (isset($_GET['updatelanguage'])) { - $this->wallabag->language->updateLanguage($_POST['language']); - } elseif (isset($_GET['uploadfile'])) { - $this->wallabag->uploadFile(); - } elseif (isset($_GET['feed'])) { - if (isset($_GET['action']) && $_GET['action'] == 'generate') { + // hello to you + $this->wallabag->login($this->referer); + } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { + $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); + $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); + } + + //allowed ONLY to logged in user + if (\Session::isLogged() === true) + { + if (isset($_GET['logout'])) { + // see you soon ! + $this->wallabag->logout(); + } elseif (isset($_GET['config'])) { + // update password + $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); + } elseif (isset($_GET['newuser'])) { + $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); + } elseif (isset($_GET['deluser'])) { + $this->wallabag->deleteUser($_POST['password4deletinguser']); + } elseif (isset($_GET['epub'])) { + $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['id'], $_GET['value']); + $epub->run(); + } elseif (isset($_GET['import'])) { + $import = $this->wallabag->import(); + $tplVars = array_merge($this->vars, $import); + } elseif (isset($_GET['empty-cache'])) { + Tools::emptyCache(); + } elseif (isset($_GET['export'])) { + $this->wallabag->export(); + } elseif (isset($_GET['updatetheme'])) { + $this->wallabag->tpl->updateTheme($_POST['theme']); + } elseif (isset($_GET['updatelanguage'])) { + $this->wallabag->language->updateLanguage($_POST['language']); + } elseif (isset($_GET['uploadfile'])) { + $this->wallabag->uploadFile(); + } elseif (isset($_GET['feed']) && isset($_GET['action']) && $_GET['action'] == 'generate') { $this->wallabag->updateToken(); } - else { - $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); - $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); + elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { + $plainUrl = new Url(base64_encode($_GET['plainurl'])); + $this->wallabag->action('add', $plainUrl); } } - elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { - $plainUrl = new Url(base64_encode($_GET['plainurl'])); - $this->wallabag->action('add', $plainUrl); - } } public function _render($file, $vars) -- cgit v1.2.3 From 6fc2c29daaadcd5075aec6bde2fd0f94274367a8 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:47:50 +0200 Subject: revert routing bad deleting --- inc/poche/Routing.class.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 0b373058..bd61a0b3 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -119,8 +119,21 @@ class Routing } elseif (isset($_GET['deluser'])) { $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { - $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['id'], $_GET['value']); - $epub->run(); + $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); + $epub->prepareData(); + $epub->produceEpub(); + } elseif (isset($_GET['mobi'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); + $mobi->produceMobi(); + } elseif (isset($_GET['send2kindle'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); + $mobi->produceMobi(TRUE); + } elseif (isset($_GET['pdf'])) { + $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); + $pdf->prepareData(); + $pdf->producePDF(); } elseif (isset($_GET['import'])) { $import = $this->wallabag->import(); $tplVars = array_merge($this->vars, $import); -- cgit v1.2.3 From fa926fb47c3d282c7662e4767923a5b7bd927a59 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:59:43 +0200 Subject: offering download for pdf file and comment in code --- inc/poche/WallabagEBooks.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index d77fe0d8..66569730 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -200,6 +200,9 @@ class WallabagMobi extends WallabagEBooks Tools::logm('Mobi file produced'); } else { + ## ## + # Not working yet !!! # + ## ## // we send file to kindle Tools::logm('Preparing to send file by email'); @@ -300,7 +303,7 @@ class WallabagPDF extends WallabagEbooks - $pdf->Output($this->bookFileName, 'I'); + $pdf->Output($this->bookFileName, 'FD'); } } \ No newline at end of file -- cgit v1.2.3 From b852df020c68ad6bc94df73cb1025c6b64ec10a6 Mon Sep 17 00:00:00 2001 From: tcit Date: Sun, 28 Sep 2014 12:18:47 +0200 Subject: add extension for pdf file --- inc/poche/WallabagEBooks.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 66569730..9dc545df 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -299,11 +299,9 @@ class WallabagPDF extends WallabagEbooks // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); - - - $pdf->Output($this->bookFileName, 'FD'); + $pdf->Output($this->bookFileName . '.pdf', 'FD'); } } \ No newline at end of file -- cgit v1.2.3 From 9f86454b48dec3c9ecfee8da224112eef0f61441 Mon Sep 17 00:00:00 2001 From: tcit Date: Sun, 28 Sep 2014 17:20:35 +0200 Subject: deleting send to kindle function --- inc/poche/Routing.class.php | 4 --- inc/poche/WallabagEBooks.class.php | 69 +++----------------------------------- 2 files changed, 4 insertions(+), 69 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index bd61a0b3..44b0e168 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -126,10 +126,6 @@ class Routing $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); $mobi->prepareData(); $mobi->produceMobi(); - } elseif (isset($_GET['send2kindle'])) { - $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); - $mobi->prepareData(); - $mobi->produceMobi(TRUE); } elseif (isset($_GET['pdf'])) { $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); $pdf->prepareData(); diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 9dc545df..2ddece61 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -165,7 +165,7 @@ class WallabagMobi extends WallabagEBooks * @author Sander Kromwijk */ - public function produceMobi($sendByMail = FALSE) + public function produceMobi() { Tools::logm('Starting to produce Mobi file'); @@ -194,70 +194,9 @@ class WallabagMobi extends WallabagEBooks } $mobi->setContentProvider($content); - if (!$sendByMail) { - // we offer file to download - $mobi->download($this->bookFileName.'.mobi'); - Tools::logm('Mobi file produced'); - } - else { - ## ## - # Not working yet !!! # - ## ## - // we send file to kindle - - Tools::logm('Preparing to send file by email'); - - $error = FALSE; - # testing Mail function - if (!function_exists('mail')) { - $error = _("Mail function is disabled. You can't send emails from your server"); - } - - $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) - $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName)) . '.mobi'; - - $file = 'cache/' . $mobiExportName; - $mobi->save($file); - - $file_size = filesize($file); - $filename = basename($file); - $handle = fopen($file, "r"); - $content = fread($handle, $file_size); - fclose($handle); - $content = chunk_split(base64_encode($content)); - - $uid = md5(uniqid(time())); - - //generate header for mail - $header = "From: wallabag <". $this->wallabag->user->email .">\r\n"; - $header .= "MIME-Version: 1.0\r\n"; - $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; - $header .= "This is a multi-part message in MIME format.\r\n"; - $header .= "--".$uid."\r\n"; - $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; - $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; - $header .= "send via wallabag\r\n\r\n"; - $header .= "--".$uid."\r\n"; - $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n"; - $header .= "Content-Transfer-Encoding: base64\r\n"; - $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; - $header .= $content."\r\n\r\n"; - $header .= "--".$uid."--"; - - # trying to get the kindle email adress - if (!$this->wallabag->user->getConfigValue('kindleemail')) - { - $error = _("You didn't set your kindle's email adress !"); - } - if (!$error) { - mail($this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); - $messages->add('s', _('The email has been sent to your kindle !')); - Tools::logm('Email sent'); - } else { - $messages->add('e', $error); - Tools::logm($error); - } - } + // we offer file to download + $mobi->download($this->bookFileName.'.mobi'); + Tools::logm('Mobi file produced'); } } -- cgit v1.2.3 From ca6c0de38015e805acf432925059dbb26241bad3 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Mon, 17 Nov 2014 17:11:33 -0500 Subject: Adjusting Template class so that _global is ignored as a theme --- inc/poche/Template.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Template.class.php b/inc/poche/Template.class.php index b686f2ec..20e9c54a 100644 --- a/inc/poche/Template.class.php +++ b/inc/poche/Template.class.php @@ -181,7 +181,7 @@ class Template extends Twig_Environment while (($theme = readdir($handle)) !== false) { # Themes are stored in a directory, so all directory names are themes # @todo move theme installation data to database - if (!is_dir(THEME . '/' . $theme) || in_array($theme, array('.', '..'))) { + if (!is_dir(THEME . '/' . $theme) || in_array($theme, array('.', '..', '_global'))) { continue; } @@ -232,4 +232,4 @@ class Template extends Twig_Environment Tools::emptyCache(); Tools::redirect('?view=config'); } -} \ No newline at end of file +} -- cgit v1.2.3 From c8b4ef7fed01c4d94ac9d2325bd2c6e97f831bad Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 19 Nov 2014 16:27:56 +0100 Subject: implementing carrot into wallabag --- inc/poche/Poche.class.php | 2 +- inc/poche/config.inc.default.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 16235474..27d6f4a6 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -812,4 +812,4 @@ class Poche } -} +} \ No newline at end of file diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index f666f468..21cbaf71 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -49,6 +49,7 @@ @define ('NOT_FLATTRABLE', '0'); @define ('FLATTRABLE', '1'); @define ('FLATTRED', '2'); +@define ('CARROT', TRUE); // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); // display or not percent of read in article view. Affects only default theme. @@ -67,4 +68,3 @@ @define ('IMPORT_LIMIT', 5); //delay between downloads (in sec) @define ('IMPORT_DELAY', 5); - -- cgit v1.2.3 From b13376e918aa157be5c0dfd53a655cc5d387f522 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 19 Nov 2014 16:35:44 +0100 Subject: fix Flattrs --- inc/poche/config.inc.default.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index f666f468..304b3924 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -67,4 +67,3 @@ @define ('IMPORT_LIMIT', 5); //delay between downloads (in sec) @define ('IMPORT_DELAY', 5); - -- cgit v1.2.3 From d25a3f13c2617d6d3f6d6433d426fab47727f038 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 19 Nov 2014 16:40:02 +0100 Subject: default deactivated --- inc/poche/config.inc.default.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 21cbaf71..de992a9c 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -49,7 +49,7 @@ @define ('NOT_FLATTRABLE', '0'); @define ('FLATTRABLE', '1'); @define ('FLATTRED', '2'); -@define ('CARROT', TRUE); +@define ('CARROT', FALSE); // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); // display or not percent of read in article view. Affects only default theme. @@ -67,4 +67,4 @@ //limit for download of articles during import @define ('IMPORT_LIMIT', 5); //delay between downloads (in sec) -@define ('IMPORT_DELAY', 5); +@define ('IMPORT_DELAY', 5); \ No newline at end of file -- cgit v1.2.3 From 85c5a1ff8d919d3d36a8125c9bbd0d9220025729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 24 Nov 2014 13:11:57 +0100 Subject: failover if theme folder doesn't exist --- inc/poche/Template.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Template.class.php b/inc/poche/Template.class.php index 20e9c54a..4d0bfdbb 100644 --- a/inc/poche/Template.class.php +++ b/inc/poche/Template.class.php @@ -24,7 +24,7 @@ class Template extends Twig_Environment $themeDirectory = (is_null($pocheUser) ? DEFAULT_THEME : $pocheUser->getConfigValue('theme')); - if ($themeDirectory === false) { + if ($themeDirectory === false || !is_dir(THEME . '/' . $themeDirectory)) { $themeDirectory = DEFAULT_THEME; } -- cgit v1.2.3 From 7c2c49d9b10104e0850f536d33588b8216416a45 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 6 Dec 2014 18:42:29 +0100 Subject: added diaspora sharing --- inc/poche/config.inc.default.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 0f88f335..3eaee3a3 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -44,6 +44,8 @@ @define ('SHARE_MAIL', TRUE); @define ('SHARE_SHAARLI', FALSE); @define ('SHAARLI_URL', 'http://myshaarliurl.com'); +@define ('SHARE_DIASPORA', FALSE); +@define ('DIASPORA_URL', 'http://diasporapod.com'); # Don't add a / at the end @define ('FLATTR', TRUE); @define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); @define ('NOT_FLATTRABLE', '0'); -- cgit v1.2.3 From 311baf86befde0557faea614ca4d13bb2bd2cc66 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 7 Dec 2014 23:36:35 +0100 Subject: implemented random button --- inc/poche/Poche.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 27d6f4a6..2a8037cc 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -445,6 +445,7 @@ class Poche $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; + $tpl_vars['random'] = rand(1,$count); } Tools::logm('display ' . $view . ' view'); break; @@ -812,4 +813,4 @@ class Poche } -} \ No newline at end of file +} -- cgit v1.2.3 From 44b95cb81deae35f58e0058910afde2f2ffb9a60 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 13 Dec 2014 22:56:30 +0100 Subject: added reload function --- inc/poche/Poche.class.php | 11 ++++++++++- inc/poche/config.inc.default.php | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 27d6f4a6..f5262a8e 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -303,6 +303,15 @@ class Poche $this->messages->add('s', _('The tag has been successfully deleted')); Tools::redirect(); break; + case 'reload_article' : + Tools::logm('reload article'); + $id = $_GET['id']; + $entry = $this->store->retrieveOneById($id, $this->user->getId()); + Tools::logm('reload url ' . $entry['url']); + $url = new Url(base64_encode($entry['url'])); + $this->action('add', $url); + break; + default: break; } @@ -812,4 +821,4 @@ class Poche } -} \ No newline at end of file +} diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 3eaee3a3..0d249c64 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -56,6 +56,7 @@ @define ('SHOW_PRINTLINK', '1'); // display or not percent of read in article view. Affects only default theme. @define ('SHOW_READPERCENT', '1'); +@define ('RELOAD_ARTICLE', TRUE); @define ('ABS_PATH', 'assets/'); @define ('DEFAULT_THEME', 'baggy'); -- cgit v1.2.3 From 5ea5310ab450035143e2f5637f9fa69773f7879b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 14 Dec 2014 15:17:39 +0100 Subject: enable showing or not for epub/mobi/pdf export buttons --- inc/poche/config.inc.default.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 3eaee3a3..a159e713 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -52,6 +52,12 @@ @define ('FLATTRABLE', '1'); @define ('FLATTRED', '2'); @define ('CARROT', FALSE); + +// ebook +@define ('EPUB', TRUE); +@define ('MOBI', FALSE); +@define ('PDF', FALSE); + // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); // display or not percent of read in article view. Affects only default theme. -- cgit v1.2.3 From e51487f93265521cf04d8752b0554bb1f05dd189 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 22 Dec 2014 16:19:29 +0100 Subject: implemented ?random url --- inc/poche/Poche.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 2a8037cc..3c7a2c5a 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -303,6 +303,14 @@ class Poche $this->messages->add('s', _('The tag has been successfully deleted')); Tools::redirect(); break; + /* 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 */ + case 'random': + $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); + $id = rand(1,$count); + Tools::logm('get a random article'); + Tools::redirect('?view=view&id=' . $id); + //$this->displayView('view', $id); + break; default: break; } @@ -445,7 +453,6 @@ class Poche $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; - $tpl_vars['random'] = rand(1,$count); } Tools::logm('display ' . $view . ' view'); break; -- cgit v1.2.3 From 37cad52229ac61b13f69440243df54e0e2a4536f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 22 Dec 2014 16:26:23 +0100 Subject: don't call flattr if flattr is disabled --- inc/poche/Poche.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 27d6f4a6..a29cb327 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -405,9 +405,12 @@ class Poche } # flattr checking - $flattr = new FlattrItem(); - $flattr->checkItem($entry['url'], $entry['id']); - + $flattr = NULL; + if (FLATTR) { + $flattr = new FlattrItem(); + $flattr->checkItem($entry['url'], $entry['id']); + } + # tags $tags = $this->store->retrieveTagsByEntry($entry['id']); @@ -812,4 +815,4 @@ class Poche } -} \ No newline at end of file +} -- cgit v1.2.3 From c86b40f014848b2f9ccf4dfbead71694a41be569 Mon Sep 17 00:00:00 2001 From: Guillaume Virlet Date: Wed, 14 May 2014 15:45:52 +0200 Subject: add message in web server log in case of authentication failure to enable the usage of fail2ban on failed login attempts --- inc/poche/Poche.class.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a29cb327..75766919 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -543,6 +543,8 @@ class Poche Tools::redirect($referer); } $this->messages->add('e', _('login failed: bad login or password')); + // log login failure in web server log to allow fail2ban usage + error_log('user '.$login.' authentication failure'); Tools::logm('login failed'); Tools::redirect(); } -- cgit v1.2.3 From 7f782e44965b005efe01d347dedd1825872b9345 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Mon, 12 Jan 2015 18:49:05 -0500 Subject: Add ability to tag an article on creation --- inc/poche/Poche.class.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a29cb327..c7c59878 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -180,6 +180,13 @@ class Poche } } + // if there are tags, add them to the new article + if (isset($_GET['tags'])) { + $_POST['value'] = $_GET['tags']; + $_POST['entry_id'] = $last_id; + $this->action('add_tag', $url); + } + $this->messages->add('s', _('the link has been added successfully')); } else { -- cgit v1.2.3 From 512e5e5bd195ea4547dc7fa29f34a9d205bd7a54 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Mon, 12 Jan 2015 19:11:45 -0500 Subject: Add ability to delete all articles matching a search --- inc/poche/Poche.class.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index c7c59878..540aa55e 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -201,18 +201,31 @@ class Poche } break; case 'delete': - $msg = 'delete link #' . $id; - if ($this->store->deleteById($id, $this->user->getId())) { - if (DOWNLOAD_PICTURES) { - Picture::removeDirectory(ABS_PATH . $id); + if (isset($_GET['search'])) { + //when we want to apply a delete to a search + $tags = array($_GET['search']); + $allentry_ids = $this->store->search($tags[0], $this->user->getId()); + $entry_ids = array(); + foreach ($allentry_ids as $eachentry) { + $entry_ids[] = $eachentry[0]; } - $this->messages->add('s', _('the link has been deleted successfully')); + } else { // delete a single article + $entry_ids = array($id); } - else { - $this->messages->add('e', _('the link wasn\'t deleted')); - $msg = 'error : can\'t delete link #' . $id; + foreach($entry_ids as $id) { + $msg = 'delete link #' . $id; + if ($this->store->deleteById($id, $this->user->getId())) { + if (DOWNLOAD_PICTURES) { + Picture::removeDirectory(ABS_PATH . $id); + } + $this->messages->add('s', _('the link has been deleted successfully')); + } + else { + $this->messages->add('e', _('the link wasn\'t deleted')); + $msg = 'error : can\'t delete link #' . $id; + } + Tools::logm($msg); } - Tools::logm($msg); Tools::redirect('?'); break; case 'toggle_fav' : -- cgit v1.2.3 From 13c7f9a462b71e89d5e252b693fc7d00aca249ec Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Mon, 12 Jan 2015 19:52:41 -0500 Subject: Add ability to mark all articles from a tag as read --- inc/poche/Poche.class.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 540aa55e..20897c61 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -240,8 +240,21 @@ class Poche } break; case 'toggle_archive' : - $this->store->archiveById($id, $this->user->getId()); - Tools::logm('archive link #' . $id); + if (isset($_GET['tag_id'])) { + //when we want to archive a whole tag + $tag_id = $_GET['tag_id']; + $allentry_ids = $this->store->retrieveEntriesByTag($tag_id, $this->user->getId()); + $entry_ids = array(); + foreach ($allentry_ids as $eachentry) { + $entry_ids[] = $eachentry[0]; + } + } else { //archive a single article + $entry_ids = array($id); + } + foreach($entry_ids as $id) { + $this->store->archiveById($id, $this->user->getId()); + Tools::logm('archive link #' . $id); + } if ( Tools::isAjaxRequest() ) { echo 1; exit; -- cgit v1.2.3 From 7fe8a9adc44a73221959263b08b516ec20bf85a0 Mon Sep 17 00:00:00 2001 From: Vincent Malley Date: Fri, 16 Jan 2015 11:42:39 -0500 Subject: [RSS] introducing query param 'limit' to restrict the number of items to display in RSS feeds. --- inc/poche/Poche.class.php | 14 ++++++++++---- inc/poche/Routing.class.php | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 20897c61..6a742019 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -784,10 +784,11 @@ class Poche * * @param $token * @param $user_id - * @param $tag_id - * @param string $type + * @param $tag_id if $type is 'tag', the id of the tag to generate feed for + * @param string $type the type of feed to generate + * @param int $limit the maximum number of items (0 means all) */ - public function generateFeeds($token, $user_id, $tag_id, $type = 'home') + public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) { $allowed_types = array('home', 'fav', 'archive', 'tag'); $config = $this->store->getConfigUser($user_id); @@ -814,8 +815,13 @@ class Poche $entries = $this->store->getEntriesByView($type, $user_id); } + // if $limit is set to zero, use all entries + if (0 == $limit) { + $limit = count($entries); + } if (count($entries) > 0) { - foreach ($entries as $entry) { + for ($i = 0; $i < min(count($entries), $limit); $i++) { + $entry = $entries[$i]; $newItem = $feed->createNewItem(); $newItem->setTitle($entry['title']); $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 5acd08ba..be06a433 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -102,7 +102,8 @@ class Routing $this->wallabag->login($this->referer); } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); - $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); + $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0); + $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit); } //allowed ONLY to logged in user -- cgit v1.2.3 From 3052cfb7cab3b37e7258f31d18624a9335c0680f Mon Sep 17 00:00:00 2001 From: kaffeeringe Date: Sun, 18 Jan 2015 21:49:05 +0100 Subject: Add Tags on Import I fixed it! And it works for me. But: I am not too good with programming. So better check the code ;-) --- inc/poche/Poche.class.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 16235474..01f919d9 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -192,6 +192,7 @@ class Poche } else { Tools::redirect('?view=home&closewin=true'); } + return $last_id; break; case 'delete': $msg = 'delete link #' . $id; @@ -625,7 +626,18 @@ class Poche $urlsInserted[] = $url; //add if (isset($record['tags']) && trim($record['tags'])) { - // @TODO: set tags + $tags = explode(' ', $record['tags']); + foreach($tags as $tag) { + $entry_id = $id; + $tag_id = $this->store->retrieveTagByValue($tag); + if ($tag_id) { + $this->store->setTagToEntry($tag_id['id'], $entry_id); + } else { + $this->store->createTag($tag); + $tag_id = $this->store->retrieveTagByValue($tag); + $this->store->setTagToEntry($tag_id['id'], $entry_id); + } + } } } -- cgit v1.2.3 From 1cedeb681f84b2c9b17f4f8b88d4fffabb15d6c8 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 19 Jan 2015 23:19:09 +0100 Subject: (kind of) fix for #1011 and little corrections for PDF export --- inc/poche/WallabagEBooks.class.php | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index bc40990b..d31939a1 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -33,7 +33,7 @@ class WallabagEBooks $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); $this->entries = array($entry); $this->bookTitle = $entry['title']; - $this->bookFileName = substr($this->bookTitle, 0, 200); + $this->bookFileName = str_replace('/', '_', substr($this->bookTitle, 0, 200)); $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) Tools::logm('Producing ebook from article ' . $this->bookTitle); break; @@ -81,6 +81,9 @@ class WallabagEpub extends WallabagEBooks public function produceEpub() { Tools::logm('Starting to produce ePub 3 file'); + + try { + $content_start = "\n" . "\n" @@ -155,6 +158,11 @@ class WallabagEpub extends WallabagEBooks $book->finalize(); $zipData = $book->sendBook($this->bookFileName); Tools::logm('Ebook produced'); + } + catch (Exception $e) { + Tools::logm('PHPePub has encountered an error : '.$e->getMessage()); + $this->wallabag->messages->add('e', $e->getMessage()); + } } } @@ -167,7 +175,7 @@ class WallabagMobi extends WallabagEBooks public function produceMobi() { - + try { Tools::logm('Starting to produce Mobi file'); $mobi = new MOBI(); $content = new MOBIFile(); @@ -197,6 +205,11 @@ class WallabagMobi extends WallabagEBooks // we offer file to download $mobi->download($this->bookFileName.'.mobi'); Tools::logm('Mobi file produced'); + } + catch (Exception $e) { + Tools::logm('PHPMobi has encountered an error : '.$e->getMessage()); + $this->wallabag->messages->add('e', $e->getMessage()); + } } } @@ -206,15 +219,16 @@ class WallabagPDF extends WallabagEbooks { Tools::logm('Starting to produce PDF file'); - + @define ('K_TCPDF_THROW_EXCEPTION_ERROR', TRUE); + try { $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); Tools::logm('Filling metadata for PDF...'); $pdf->SetCreator(PDF_CREATOR); - $pdf->SetAuthor(''); + $pdf->SetAuthor('wallabag'); $pdf->SetTitle($this->bookTitle); - $pdf->SetSubject('TCPDF Tutorial'); - $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); + $pdf->SetSubject('Articles via wallabag'); + $pdf->SetKeywords('wallabag'); Tools::logm('Adding introduction...'); $pdf->AddPage(); @@ -229,18 +243,26 @@ class WallabagPDF extends WallabagEbooks $i = 1; Tools::logm('Adding actual content...'); foreach ($this->entries as $item) { + $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); + foreach ($tags as $tag) { + $pdf->SetKeywords($tag['value']); + } $pdf->AddPage(); $html = '

' . $item['title'] . '

'; $html .= $item['content']; $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); - $i = $i+1; } // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); - + $pdf->Output($this->bookFileName . '.pdf', 'FD'); + } + catch (Exception $e) { + Tools::logm('TCPDF has encountered an error : '.$e->getMessage()); + $this->wallabag->messages->add('e', $e->getMessage()); + } } } -- cgit v1.2.3 From 9a490ad63a08c619bb45ad9bf090790c31ebe92e Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 20 Jan 2015 00:02:21 +0100 Subject: from spaces to commas --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5a0edbe4..81a18c86 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -664,7 +664,7 @@ class Poche $urlsInserted[] = $url; //add if (isset($record['tags']) && trim($record['tags'])) { - $tags = explode(' ', $record['tags']); + $tags = explode(',', $record['tags']); foreach($tags as $tag) { $entry_id = $id; $tag_id = $this->store->retrieveTagByValue($tag); -- cgit v1.2.3 From 121691e90026dcfaaecef0a1db07d40cd43a9278 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 23 Jan 2015 16:34:56 +0100 Subject: working on registration support --- inc/poche/Poche.class.php | 4 ++++ inc/poche/Routing.class.php | 10 +++++++++- inc/poche/Tools.class.php | 2 +- inc/poche/config.inc.default.php | 4 +++- 4 files changed, 17 insertions(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 81a18c86..36c8693c 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -76,6 +76,7 @@ class Poche */ public function createNewUser($username, $password, $email = "") { + Tools::logm('Trying to create a new user...'); if (!empty($username) && !empty($password)){ $newUsername = filter_var($username, FILTER_SANITIZE_STRING); $email = filter_var($email, FILTER_SANITIZE_STRING); @@ -96,6 +97,9 @@ class Poche Tools::redirect(); } } + else { + Tools::logm('Password or username were empty'); + } } /** diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index be06a433..8d6abefd 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -67,6 +67,12 @@ class Routing $this->wallabag->action($this->action, $this->url, $this->id); $tplFile = Tools::getTplFile($this->view); $tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id)); + } elseif(ALLOW_REGISTER && isset($_GET['registerform'])) { + Tools::logm('register'); + $tplFile = Tools::getTplFile('register'); + } elseif (ALLOW_REGISTER && isset($_GET['register'])){ + $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); + Tools::redirect(); } elseif(isset($_SERVER['PHP_AUTH_USER'])) { if($this->wallabag->store->userExists($_SERVER['PHP_AUTH_USER'])) { $this->wallabag->login($this->referer); @@ -104,7 +110,9 @@ class Routing $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0); $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit); - } + } //elseif (ALLOW_REGISTER && isset($_GET['register'])) { + //$this->wallabag->register + //} //allowed ONLY to logged in user if (\Session::isLogged() === true) 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 { $views = array( 'install', 'import', 'export', 'config', 'tags', - 'edit-tags', 'view', 'login', 'error', 'about' + 'edit-tags', 'view', 'login', 'error', 'about', 'register' ); return (in_array($view, $views) ? $view . '.twig' : 'home.twig'); diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index a159e713..3156b56c 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -31,7 +31,9 @@ @define ('SSL_PORT', 443); @define ('MODE_DEMO', FALSE); -@define ('DEBUG_POCHE', FALSE); +@define ('DEBUG_POCHE', TRUE); + +@define ('ALLOW_REGISTER', TRUE); //default level of error reporting in application. Developers should override it in their config.inc.php: set to E_ALL. @define ('ERROR_REPORTING', E_ALL & ~E_NOTICE); -- cgit v1.2.3 From 1fbef3bfb57b3f73e6817115f10b5876dd0e57ef Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 24 Jan 2015 12:54:58 +0100 Subject: resetting debug to false --- inc/poche/config.inc.default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 3156b56c..000faf1c 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -31,7 +31,7 @@ @define ('SSL_PORT', 443); @define ('MODE_DEMO', FALSE); -@define ('DEBUG_POCHE', TRUE); +@define ('DEBUG_POCHE', FALSE); @define ('ALLOW_REGISTER', TRUE); -- cgit v1.2.3 From a3a9e75e625b78de371dad2d319ee3a84b7a75c2 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 24 Jan 2015 14:35:03 +0100 Subject: correct a bug when email was not sended when creating a new user --- inc/poche/Routing.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index be06a433..a8d00b89 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -116,7 +116,7 @@ class Routing // update password $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); } elseif (isset($_GET['newuser'])) { - $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); + $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']); } elseif (isset($_GET['deluser'])) { $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { -- cgit v1.2.3 From 3e1daa4c9016944b444829151334ab87cd3d3dcb Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 24 Jan 2015 15:09:18 +0100 Subject: allow to send confirmation emails when creating a new user --- inc/poche/Poche.class.php | 27 +++++++++++++++++++++++---- inc/poche/Routing.class.php | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 81a18c86..adb335c9 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -74,16 +74,35 @@ class Poche /** * Creates a new user */ - public function createNewUser($username, $password, $email = "") + public function createNewUser($username, $password, $email = "", $internalRegistration = false) { if (!empty($username) && !empty($password)){ $newUsername = filter_var($username, FILTER_SANITIZE_STRING); $email = filter_var($email, FILTER_SANITIZE_STRING); if (!$this->store->userExists($newUsername)){ if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { - Tools::logm('The new user ' . $newUsername . ' has been installed'); - $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to logout ?'), $newUsername)); - Tools::redirect(); + if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { + // if internal registration + $body_internal = "Hi,\r\n\r\nSomeone just created an account for you on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; + // if external (public) registration + $body = "Hi, \r\n\r\nYou've just created an account on " . Tools::getPocheUrl() . . ".\r\nHave fun with it !"; + $body = $internalRegistration ? $body_internal : $body; + $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) + if (mail($email, sprintf(_('Your new wallabag account on '), Tools::getPocheUrl()), $body, 'From: {$email}')) { + Tools::logm('The user ' . $newUsername . ' has been emailed'); + $this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s.'), $newUsername, $email)); + + } else { + Tools::logm('A problem has been encountered while sending an email'); + $this->messages->add('e', _('A problem has been encountered while sending an email'); + } + } else { + Tools::logm('The user has been created, but the server did not authorize sending emails'); + $this->messages->add('i', _('The server did not authorize sending an email'); + } + Tools::logm('The new user ' . $newUsername . ' has been installed'); + $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to logout ?'), $newUsername)); + Tools::redirect(); } else { Tools::logm('error during adding new user'); diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index a8d00b89..b8cab0ec 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -116,7 +116,7 @@ class Routing // update password $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); } elseif (isset($_GET['newuser'])) { - $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']); + $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail'], true); } elseif (isset($_GET['deluser'])) { $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { -- cgit v1.2.3 From 1be071f9f0fba7c93f114a886ff19199955a3f02 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 24 Jan 2015 15:43:45 +0100 Subject: fix syntax errors --- inc/poche/Poche.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index adb335c9..e89e9d30 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -85,20 +85,20 @@ class Poche // if internal registration $body_internal = "Hi,\r\n\r\nSomeone just created an account for you on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; // if external (public) registration - $body = "Hi, \r\n\r\nYou've just created an account on " . Tools::getPocheUrl() . . ".\r\nHave fun with it !"; + $body = "Hi, \r\n\r\nYou've just created an account on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; $body = $internalRegistration ? $body_internal : $body; $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) - if (mail($email, sprintf(_('Your new wallabag account on '), Tools::getPocheUrl()), $body, 'From: {$email}')) { + if (mail($email, sprintf(_('Your new wallabag account on '), Tools::getPocheUrl()), $body, 'X-Mailer: PHP/' . phpversion())) { Tools::logm('The user ' . $newUsername . ' has been emailed'); $this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s.'), $newUsername, $email)); } else { Tools::logm('A problem has been encountered while sending an email'); - $this->messages->add('e', _('A problem has been encountered while sending an email'); + $this->messages->add('e', _('A problem has been encountered while sending an email')); } } else { Tools::logm('The user has been created, but the server did not authorize sending emails'); - $this->messages->add('i', _('The server did not authorize sending an email'); + $this->messages->add('i', _('The server did not authorize sending an email')); } Tools::logm('The new user ' . $newUsername . ' has been installed'); $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to logout ?'), $newUsername)); -- cgit v1.2.3 From 42ac69337f6538593e4375a38fb410b13c6cb660 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 26 Jan 2015 00:16:14 +0100 Subject: fix for spaces in .mobi filenames --- inc/poche/WallabagEBooks.class.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index d31939a1..afcf4dbf 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -202,6 +202,9 @@ class WallabagMobi extends WallabagEBooks } $mobi->setContentProvider($content); + // we strip spaces because the browser inside Kindle Devices doesn't likes spaces + $this->bookFileName = str_replace(' ', '_', $this->bookFileName); + // we offer file to download $mobi->download($this->bookFileName.'.mobi'); Tools::logm('Mobi file produced'); -- cgit v1.2.3 From 3829c54bc5ceff31cb72e686b3c020ea2ac2a5b2 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 26 Jan 2015 17:44:52 +0100 Subject: fix for special caracters in .mobi filenames --- inc/poche/WallabagEBooks.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index afcf4dbf..55831571 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -202,8 +202,8 @@ class WallabagMobi extends WallabagEBooks } $mobi->setContentProvider($content); - // we strip spaces because the browser inside Kindle Devices doesn't likes spaces - $this->bookFileName = str_replace(' ', '_', $this->bookFileName); + // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9 + $this->bookFileName = preg_replace('/[^A-Za-z0-9\-]/', '', $this->bookFileName); // we offer file to download $mobi->download($this->bookFileName.'.mobi'); -- cgit v1.2.3 From 89637c2a1dcc114b17a8f7eef493b51315e1a6ac Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 1 Feb 2015 12:22:14 +0100 Subject: added reload icon and fixed a bug where random could redirect to deleted articles --- inc/poche/Poche.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index fb74ab9a..f9928145 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -349,8 +349,11 @@ class Poche /* 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 */ case 'random': - $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); - $id = rand(1,$count); + $id = 0; + while ($this->store->retrieveOneById($id,$this->user->getId()) == null) { + $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); + $id = rand(1,$count); + } Tools::logm('get a random article'); Tools::redirect('?view=view&id=' . $id); //$this->displayView('view', $id); -- cgit v1.2.3 From 1c91178932cd5b48d793261c6631697186853a93 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 4 Feb 2015 23:37:37 +0100 Subject: fix autoclose (#984) and bookmarklet mode --- inc/poche/Poche.class.php | 4 ++-- inc/poche/Routing.class.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index f9928145..a601f0a8 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -195,9 +195,9 @@ class Poche } if ($autoclose == TRUE) { - Tools::redirect('?view=home'); + Tools::redirect('?view=home&closewin=true'); } else { - Tools::redirect('?view=home&closewin=true'); + Tools::redirect('?view=home'); } return $last_id; break; diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index a8d00b89..709831d5 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -33,6 +33,7 @@ class Routing $this->view = Tools::checkVar('view', 'home'); $this->action = Tools::checkVar('action'); $this->id = Tools::checkVar('id'); + $this->autoclose = Tools::checkVar('autoclose',FALSE); $_SESSION['sort'] = Tools::checkVar('sort', 'id'); $this->url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); } @@ -64,7 +65,7 @@ class Routing $tplVars = array(); if (\Session::isLogged()) { - $this->wallabag->action($this->action, $this->url, $this->id); + $this->wallabag->action($this->action, $this->url, $this->id, FALSE, $this->autoclose); $tplFile = Tools::getTplFile($this->view); $tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id)); } elseif(isset($_SERVER['PHP_AUTH_USER'])) { -- cgit v1.2.3 From 571b99e8045ab45bfa04bbc2a90dc566dba59452 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 4 Feb 2015 23:50:33 +0100 Subject: added evernote support --- inc/poche/config.inc.default.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index aaaf12a6..91b50c24 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -44,6 +44,7 @@ @define ('SHARE_MAIL', TRUE); @define ('SHARE_SHAARLI', FALSE); @define ('SHAARLI_URL', 'http://myshaarliurl.com'); +@define ('SHARE_EVERNOTE', FALSE); @define ('SHARE_DIASPORA', FALSE); @define ('DIASPORA_URL', 'http://diasporapod.com'); # Don't add a / at the end @define ('FLATTR', TRUE); -- cgit v1.2.3 From fde4cf0616e68d7b94f0991c1fcb434de4567c17 Mon Sep 17 00:00:00 2001 From: Eric Priou aka erixtekila Date: Thu, 5 Feb 2015 14:19:03 +0100 Subject: Fix fetched entries when localized --- inc/poche/Database.class.php | 4 ++-- inc/poche/Poche.class.php | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index f6ba4708..6bac0f5d 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -293,7 +293,7 @@ class Database { $sql_limit = "LIMIT ".$limit." OFFSET 0"; } - $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=? ORDER BY id " . $sql_limit; + $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=? ORDER BY id " . $sql_limit; $query = $this->executeQuery($sql, array($user_id)); $entries = $query->fetchAll(); @@ -302,7 +302,7 @@ class Database { public function retrieveUnfetchedEntriesCount($user_id) { - $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?"; + $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=?"; $query = $this->executeQuery($sql, array($user_id)); list($count) = $query->fetch(); diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a601f0a8..d096de91 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -740,17 +740,23 @@ class Poche $purifier = $this->_getPurifier(); foreach($items as $item) { $url = new Url(base64_encode($item['url'])); - Tools::logm('Fetching article ' . $item['id']); - $content = Tools::getPageContent($url); - $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); - $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); - - // clean content to prevent xss attack - - $title = $purifier->purify($title); - $body = $purifier->purify($body); - $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); - Tools::logm('Article ' . $item['id'] . ' updated.'); + if( $url->isCorrect() ) + { + Tools::logm('Fetching article ' . $item['id']); + $content = Tools::getPageContent($url); + $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); + $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); + + // clean content to prevent xss attack + + $title = $purifier->purify($title); + $body = $purifier->purify($body); + $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); + Tools::logm('Article ' . $item['id'] . ' updated.'); + } else + { + Tools::logm('Unvalid URL (' . $item['url'] .') to fetch for article ' . $item['id']); + } } } } -- cgit v1.2.3 From 6cb5e1c9f511996d52b45b459bb26047f0dead38 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 13 Feb 2015 19:10:22 +0100 Subject: improvements to internal registration and translations --- inc/poche/Poche.class.php | 47 ++++++++++++++++++++++++++-------------- inc/poche/config.inc.default.php | 3 +++ 2 files changed, 34 insertions(+), 16 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index b26826f1..8ade91b4 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -81,25 +81,40 @@ class Poche $email = filter_var($email, FILTER_SANITIZE_STRING); if (!$this->store->userExists($newUsername)){ if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { - if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { - // if internal registration - $body_internal = "Hi,\r\n\r\nSomeone just created an account for you on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; - // if external (public) registration - $body = "Hi, \r\n\r\nYou've just created an account on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; - $body = $internalRegistration ? $body_internal : $body; - $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) - if (mail($email, sprintf(_('Your new wallabag account on '), Tools::getPocheUrl()), $body, 'X-Mailer: PHP/' . phpversion())) { - Tools::logm('The user ' . $newUsername . ' has been emailed'); - $this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s.'), $newUsername, $email)); + if ($email != "") { // if email is filled + if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { + + // if internal registration + $body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) . + "\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) ."\r\n\r\n" . + _('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" . + _('Have fun with it !') . "\r\n\r\n" . + _('This is an automatically generated message, no one will answer if you respond to it.'); + // if external (public) registration + $body = "Hi, " . $newUsername . "\r\n\r\nYou've just created a wallabag account on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; + $body = $internalRegistration ? $body_internal : $body; + + $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) + if (mail($email, sprintf(_('Your new wallabag account on %1$s'), Tools::getPocheUrl()), $body, + 'X-Mailer: PHP/' . phpversion() . "\r\n" . + 'Content-type: text/plain; charset=UTF-8' . "\r\n" . + "From: " . $newUsername . "@" . gethostname() . "\r\n")) { + Tools::logm('The user ' . $newUsername . ' has been emailed'); + $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)); + + } else { + Tools::logm('A problem has been encountered while sending an email'); + $this->messages->add('e', _('A problem has been encountered while sending an email')); + } } else { - Tools::logm('A problem has been encountered while sending an email'); - $this->messages->add('e', _('A problem has been encountered while sending an email')); + Tools::logm('The user has been created, but the server did not authorize sending emails'); + $this->messages->add('i', _('The server did not authorize sending a confirmation email')); } - } else { - Tools::logm('The user has been created, but the server did not authorize sending emails'); - $this->messages->add('i', _('The server did not authorize sending an email')); - } + } else { + Tools::logm('The user has been created, but no email was saved, so no confimation email was sent'); + $this->messages->add('i', _('The user was created, but no email was sent because email was not filled in')); + } Tools::logm('The new user ' . $newUsername . ' has been installed'); $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to logout ?'), $newUsername)); Tools::redirect(); diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 91b50c24..fbf4ae9a 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -59,6 +59,9 @@ @define ('MOBI', FALSE); @define ('PDF', FALSE); +// registration +@define ('SEND_CONFIRMATION_EMAIL', TRUE); + // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); // display or not percent of read in article view. Affects only default theme. -- cgit v1.2.3 From dc6ec987585a1c51f678c404143e37b0d844d796 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 13 Feb 2015 19:14:56 +0100 Subject: just a reminder --- inc/poche/config.inc.default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index fbf4ae9a..0fd9bc0e 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -60,7 +60,7 @@ @define ('PDF', FALSE); // registration -@define ('SEND_CONFIRMATION_EMAIL', TRUE); +@define ('SEND_CONFIRMATION_EMAIL', TRUE); // TO BE CHANGED DEPENDING ON POLL // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); -- cgit v1.2.3 From f2321633b9dcc806b3c036a742bde1e4c9bcbef9 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 13 Feb 2015 19:39:48 +0100 Subject: couple improvements, translations --- inc/poche/Poche.class.php | 8 ++++++-- inc/poche/Routing.class.php | 2 +- inc/poche/config.inc.default.php | 3 +-- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index cd7578e3..a91a3f8f 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -93,7 +93,9 @@ class Poche _('This is an automatically generated message, no one will answer if you respond to it.'); // if external (public) registration - $body = "Hi, " . $newUsername . "\r\n\r\nYou've just created a wallabag account on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; + $body = sprintf(_('Hi, %1$s'), $newUsername) . "\r\n\r\n" . + sprintf(_('You\'ve just created a wallabag account on %1$s.'), Tools::getPocheUrl()) . + "\r\n\r\n" . _("Have fun with it !"); $body = $internalRegistration ? $body_internal : $body; $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) @@ -117,7 +119,9 @@ class Poche $this->messages->add('i', _('The user was created, but no email was sent because email was not filled in')); } Tools::logm('The new user ' . $newUsername . ' has been installed'); - $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to logout ?'), $newUsername)); + if (\Session::isLogged()) { + $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to logout ?'), $newUsername)); + } Tools::redirect(); } else { diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index e9b67771..177b74d5 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -72,7 +72,7 @@ class Routing Tools::logm('register'); $tplFile = Tools::getTplFile('register'); } elseif (ALLOW_REGISTER && isset($_GET['register'])){ - $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); + $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']); Tools::redirect(); } elseif(isset($_SERVER['PHP_AUTH_USER'])) { if($this->wallabag->store->userExists($_SERVER['PHP_AUTH_USER'])) { diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index e569dddd..7c27856d 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -33,8 +33,6 @@ @define ('MODE_DEMO', FALSE); @define ('DEBUG_POCHE', FALSE); -@define ('ALLOW_REGISTER', TRUE); - //default level of error reporting in application. Developers should override it in their config.inc.php: set to E_ALL. @define ('ERROR_REPORTING', E_ALL & ~E_NOTICE); @@ -63,6 +61,7 @@ // registration @define ('SEND_CONFIRMATION_EMAIL', TRUE); // TO BE CHANGED DEPENDING ON POLL +@define ('ALLOW_REGISTER', TRUE); // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); -- cgit v1.2.3 From 698eda739e705f5605711af927eb5e3720c7c97c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 14 Feb 2015 12:35:22 +0100 Subject: mainly css improvements --- inc/poche/Poche.class.php | 4 +++- inc/poche/config.inc.default.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a91a3f8f..e37d7c6c 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -85,7 +85,7 @@ class Poche if ($email != "") { // if email is filled if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { - // if internal registration + // if internal registration from config screen $body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) . "\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) ."\r\n\r\n" . _('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" . @@ -96,6 +96,7 @@ class Poche $body = sprintf(_('Hi, %1$s'), $newUsername) . "\r\n\r\n" . sprintf(_('You\'ve just created a wallabag account on %1$s.'), Tools::getPocheUrl()) . "\r\n\r\n" . _("Have fun with it !"); + $body = $internalRegistration ? $body_internal : $body; $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) @@ -105,6 +106,7 @@ class Poche "From: " . $newUsername . "@" . gethostname() . "\r\n")) { Tools::logm('The user ' . $newUsername . ' has been emailed'); $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)); + Tools::redirect('?'); } else { Tools::logm('A problem has been encountered while sending an email'); diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 7c27856d..6750383e 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -60,7 +60,7 @@ @define ('PDF', FALSE); // registration -@define ('SEND_CONFIRMATION_EMAIL', TRUE); // TO BE CHANGED DEPENDING ON POLL +@define ('SEND_CONFIRMATION_EMAIL', FALSE); @define ('ALLOW_REGISTER', TRUE); // display or not print link in article view -- cgit v1.2.3 From 952faeeb312e7461e4ca69fb236c14ee780d3fc5 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 14 Feb 2015 12:36:00 +0100 Subject: forgot this file --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e37d7c6c..6d4ce137 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -114,7 +114,7 @@ class Poche } } else { Tools::logm('The user has been created, but the server did not authorize sending emails'); - $this->messages->add('i', _('The server did not authorize sending a confirmation email')); + $this->messages->add('i', _('The server did not authorize sending a confirmation email, but the user was created.')); } } else { Tools::logm('The user has been created, but no email was saved, so no confimation email was sent'); -- cgit v1.2.3 From 054c9d8838e6d339f46d22f90655576fa1d1231d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 14 Feb 2015 15:12:02 +0100 Subject: (definitely) fixed utf8mb4 and check if user already exists in database before installing first user --- inc/poche/Database.class.php | 13 +++++++++---- inc/poche/config.inc.default.php | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 6bac0f5d..a987b7cc 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -31,10 +31,15 @@ class Database { $this->handle = new PDO($db_path); break; case 'mysql': - $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; - $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', - )); + if (MYSQL_USE_UTF8MB4) { + $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', + )); + } else { + $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); + } break; case 'postgres': $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 6750383e..16b96f7e 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -20,6 +20,7 @@ @define ('STORAGE_DB', 'poche'); @define ('STORAGE_USER', 'poche'); @define ('STORAGE_PASSWORD', 'poche'); +@define ('MYSQL_USE_UTF8MB4', FALSE); // This should be false unless you know what it is ################################################################################# # Do not trespass unless you know what you are doing -- cgit v1.2.3 From 50b752c21e9f4d0e9153db091f5293c927cd1735 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 14 Feb 2015 15:12:56 +0100 Subject: set registration to false --- inc/poche/config.inc.default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 16b96f7e..09d3aa9a 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -61,8 +61,8 @@ @define ('PDF', FALSE); // registration +@define ('ALLOW_REGISTER', FALSE); @define ('SEND_CONFIRMATION_EMAIL', FALSE); -@define ('ALLOW_REGISTER', TRUE); // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); -- cgit v1.2.3 From c35753dd3ecd864e4b6118c93cc2006d16cc3293 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 14 Feb 2015 16:23:39 +0100 Subject: support GB english --- inc/poche/Language.class.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/poche') diff --git a/inc/poche/Language.class.php b/inc/poche/Language.class.php index 420f2fb9..6a1944c7 100644 --- a/inc/poche/Language.class.php +++ b/inc/poche/Language.class.php @@ -18,6 +18,7 @@ class Language 'cs_CZ.utf8' => 'čeština', 'de_DE.utf8' => 'German', 'en_EN.utf8' => 'English', + 'en_GB.utf8' => 'English (GB)', 'en_US.utf8' => 'English (US)', 'es_ES.utf8' => 'Español', 'fa_IR.utf8' => 'فارسی', -- cgit v1.2.3 From d523c9939968d894d56b617be5210bd936e10c39 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 15 Feb 2015 21:17:50 +0100 Subject: Delete en_EN language (GB and US are available) --- inc/poche/Language.class.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Language.class.php b/inc/poche/Language.class.php index 6a1944c7..962159c0 100644 --- a/inc/poche/Language.class.php +++ b/inc/poche/Language.class.php @@ -17,7 +17,6 @@ class Language private $languageNames = array( 'cs_CZ.utf8' => 'čeština', 'de_DE.utf8' => 'German', - 'en_EN.utf8' => 'English', 'en_GB.utf8' => 'English (GB)', 'en_US.utf8' => 'English (US)', 'es_ES.utf8' => 'Español', -- cgit v1.2.3 From 6b60741600321e4a2c414e91595b09d35516a3ea Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Feb 2015 00:43:18 +0100 Subject: alternative random function to fix #1082 --- inc/poche/Database.class.php | 8 ++++++++ inc/poche/Poche.class.php | 11 +++++------ 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index a987b7cc..210ebb74 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -411,6 +411,14 @@ class Database { return $count; } + public function getRandomId($row, $user_id) { + $sql = "SELECT id FROM entries WHERE user_id=? LIMIT 1 OFFSET ? "; + $params = array($user_id, $row); + $query = $this->executeQuery($sql, $params); + + return $query->fetchAll(); + } + public function updateContent($id, $content, $user_id) { diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 6d4ce137..4b85d52f 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -393,13 +393,12 @@ class Poche /* 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 */ case 'random': - $id = 0; - while ($this->store->retrieveOneById($id,$this->user->getId()) == null) { - $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); - $id = rand(1,$count); - } + $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); + $id_query = $this->store->getRandomId(rand(1,$count)-1, $this->user->getId()); + $id = $id_query[0]; Tools::logm('get a random article'); - Tools::redirect('?view=view&id=' . $id); + Tools::redirect('?view=view&id=' . $id[0]); + //$this->displayView('view', $id); break; default: -- cgit v1.2.3 From cdee5e65701330e0b740640f471228d8b9b02a91 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Feb 2015 15:18:24 +0100 Subject: much better fix for #1082 --- inc/poche/Database.class.php | 12 +++++++----- inc/poche/Poche.class.php | 11 +++++------ 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 210ebb74..65675afe 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -411,12 +411,14 @@ class Database { return $count; } - public function getRandomId($row, $user_id) { - $sql = "SELECT id FROM entries WHERE user_id=? LIMIT 1 OFFSET ? "; - $params = array($user_id, $row); - $query = $this->executeQuery($sql, $params); + public function getRandomId($user_id) { + $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; + $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id); + $query = $this->executeQuery($sql, $params); + $id = $query->fetchAll(); - return $query->fetchAll(); + return $id; } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4b85d52f..481382ec 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -393,13 +393,12 @@ class Poche /* 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 */ case 'random': - $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); - $id_query = $this->store->getRandomId(rand(1,$count)-1, $this->user->getId()); - $id = $id_query[0]; Tools::logm('get a random article'); - Tools::redirect('?view=view&id=' . $id[0]); - - //$this->displayView('view', $id); + if ($this->store->getRandomId($this->user->getId())) { + $id = $this->store->getRandomId($this->user->getId())[0]; + Tools::redirect('?view=view&id=' . $id[0]); + Tools::logm('got the article with id ' . $id[0]); + } break; default: break; -- cgit v1.2.3 From 336797f309200bd535324ab161427b39ab3d7487 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Feb 2015 16:57:16 +0100 Subject: adapt for php < 5.4 Still not obsolete. :( --- inc/poche/Poche.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 481382ec..9424e3ff 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -395,7 +395,8 @@ class Poche case 'random': Tools::logm('get a random article'); if ($this->store->getRandomId($this->user->getId())) { - $id = $this->store->getRandomId($this->user->getId())[0]; + $id_array = $this->store->getRandomId($this->user->getId()); + $id = $id_array[0]; Tools::redirect('?view=view&id=' . $id[0]); Tools::logm('got the article with id ' . $id[0]); } -- cgit v1.2.3 From df89c6f71adebfdb754ec3eb2fd775d8efbdb280 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 18 Feb 2015 19:16:42 +0100 Subject: Change message type from success to error See #1096 --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 9424e3ff..fd2600f3 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -754,7 +754,7 @@ class Poche Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).'); } else { - $this->messages->add('s', _('Did you forget to select a file?')); + $this->messages->add('e', _('Did you forget to select a file?')); } // file parsing finished here // now download article contents if any -- cgit v1.2.3