diff options
author | Thomas Citharel <tcit@tcit.fr> | 2015-02-13 19:15:31 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2015-02-13 19:15:31 +0100 |
commit | 0eae6d14b8858005919cc3069799f77008a81d29 (patch) | |
tree | 9c18566ddada5bf8e391a7fa96f27cfc71471f1b /inc/poche | |
parent | 1fbef3bfb57b3f73e6817115f10b5876dd0e57ef (diff) | |
parent | dc6ec987585a1c51f678c404143e37b0d844d796 (diff) | |
download | wallabag-0eae6d14b8858005919cc3069799f77008a81d29.tar.gz wallabag-0eae6d14b8858005919cc3069799f77008a81d29.tar.zst wallabag-0eae6d14b8858005919cc3069799f77008a81d29.zip |
Merge branch 'dev' into register
Diffstat (limited to 'inc/poche')
-rwxr-xr-x | inc/poche/Database.class.php | 4 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 95 | ||||
-rwxr-xr-x | inc/poche/Routing.class.php | 5 | ||||
-rw-r--r-- | inc/poche/WallabagEBooks.class.php | 3 | ||||
-rwxr-xr-x | inc/poche/config.inc.default.php | 5 |
5 files changed, 91 insertions, 21 deletions
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 { | |||
293 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; | 293 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; |
294 | } | 294 | } |
295 | 295 | ||
296 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=? ORDER BY id " . $sql_limit; | 296 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=? ORDER BY id " . $sql_limit; |
297 | $query = $this->executeQuery($sql, array($user_id)); | 297 | $query = $this->executeQuery($sql, array($user_id)); |
298 | $entries = $query->fetchAll(); | 298 | $entries = $query->fetchAll(); |
299 | 299 | ||
@@ -302,7 +302,7 @@ class Database { | |||
302 | 302 | ||
303 | public function retrieveUnfetchedEntriesCount($user_id) | 303 | public function retrieveUnfetchedEntriesCount($user_id) |
304 | { | 304 | { |
305 | $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?"; | 305 | $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=?"; |
306 | $query = $this->executeQuery($sql, array($user_id)); | 306 | $query = $this->executeQuery($sql, array($user_id)); |
307 | list($count) = $query->fetch(); | 307 | list($count) = $query->fetch(); |
308 | 308 | ||
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 36c8693c..cd7578e3 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -74,7 +74,7 @@ class Poche | |||
74 | /** | 74 | /** |
75 | * Creates a new user | 75 | * Creates a new user |
76 | */ | 76 | */ |
77 | public function createNewUser($username, $password, $email = "") | 77 | public function createNewUser($username, $password, $email = "", $internalRegistration = false) |
78 | { | 78 | { |
79 | Tools::logm('Trying to create a new user...'); | 79 | Tools::logm('Trying to create a new user...'); |
80 | if (!empty($username) && !empty($password)){ | 80 | if (!empty($username) && !empty($password)){ |
@@ -82,9 +82,43 @@ class Poche | |||
82 | $email = filter_var($email, FILTER_SANITIZE_STRING); | 82 | $email = filter_var($email, FILTER_SANITIZE_STRING); |
83 | if (!$this->store->userExists($newUsername)){ | 83 | if (!$this->store->userExists($newUsername)){ |
84 | if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { | 84 | if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { |
85 | Tools::logm('The new user ' . $newUsername . ' has been installed'); | 85 | if ($email != "") { // if email is filled |
86 | $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername)); | 86 | if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { |
87 | Tools::redirect(); | 87 | |
88 | // if internal registration | ||
89 | $body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) . | ||
90 | "\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) ."\r\n\r\n" . | ||
91 | _('Note : The password has been chosen by the person who created your account. Get in touch with that person to know your password and change it as soon as possible') . "\r\n\r\n" . | ||
92 | _('Have fun with it !') . "\r\n\r\n" . | ||
93 | _('This is an automatically generated message, no one will answer if you respond to it.'); | ||
94 | |||
95 | // if external (public) registration | ||
96 | $body = "Hi, " . $newUsername . "\r\n\r\nYou've just created a wallabag account on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; | ||
97 | $body = $internalRegistration ? $body_internal : $body; | ||
98 | |||
99 | $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) | ||
100 | if (mail($email, sprintf(_('Your new wallabag account on %1$s'), Tools::getPocheUrl()), $body, | ||
101 | 'X-Mailer: PHP/' . phpversion() . "\r\n" . | ||
102 | 'Content-type: text/plain; charset=UTF-8' . "\r\n" . | ||
103 | "From: " . $newUsername . "@" . gethostname() . "\r\n")) { | ||
104 | Tools::logm('The user ' . $newUsername . ' has been emailed'); | ||
105 | $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)); | ||
106 | |||
107 | } else { | ||
108 | Tools::logm('A problem has been encountered while sending an email'); | ||
109 | $this->messages->add('e', _('A problem has been encountered while sending an email')); | ||
110 | } | ||
111 | } else { | ||
112 | Tools::logm('The user has been created, but the server did not authorize sending emails'); | ||
113 | $this->messages->add('i', _('The server did not authorize sending a confirmation email')); | ||
114 | } | ||
115 | } else { | ||
116 | Tools::logm('The user has been created, but no email was saved, so no confimation email was sent'); | ||
117 | $this->messages->add('i', _('The user was created, but no email was sent because email was not filled in')); | ||
118 | } | ||
119 | Tools::logm('The new user ' . $newUsername . ' has been installed'); | ||
120 | $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername)); | ||
121 | Tools::redirect(); | ||
88 | } | 122 | } |
89 | else { | 123 | else { |
90 | Tools::logm('error during adding new user'); | 124 | Tools::logm('error during adding new user'); |
@@ -199,9 +233,9 @@ class Poche | |||
199 | } | 233 | } |
200 | 234 | ||
201 | if ($autoclose == TRUE) { | 235 | if ($autoclose == TRUE) { |
202 | Tools::redirect('?view=home'); | 236 | Tools::redirect('?view=home&closewin=true'); |
203 | } else { | 237 | } else { |
204 | Tools::redirect('?view=home&closewin=true'); | 238 | Tools::redirect('?view=home'); |
205 | } | 239 | } |
206 | return $last_id; | 240 | return $last_id; |
207 | break; | 241 | break; |
@@ -341,6 +375,27 @@ class Poche | |||
341 | $this->messages->add('s', _('The tag has been successfully deleted')); | 375 | $this->messages->add('s', _('The tag has been successfully deleted')); |
342 | Tools::redirect(); | 376 | Tools::redirect(); |
343 | break; | 377 | break; |
378 | |||
379 | case 'reload_article' : | ||
380 | Tools::logm('reload article'); | ||
381 | $id = $_GET['id']; | ||
382 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); | ||
383 | Tools::logm('reload url ' . $entry['url']); | ||
384 | $url = new Url(base64_encode($entry['url'])); | ||
385 | $this->action('add', $url); | ||
386 | break; | ||
387 | |||
388 | /* 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 */ | ||
389 | case 'random': | ||
390 | $id = 0; | ||
391 | while ($this->store->retrieveOneById($id,$this->user->getId()) == null) { | ||
392 | $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); | ||
393 | $id = rand(1,$count); | ||
394 | } | ||
395 | Tools::logm('get a random article'); | ||
396 | Tools::redirect('?view=view&id=' . $id); | ||
397 | //$this->displayView('view', $id); | ||
398 | break; | ||
344 | default: | 399 | default: |
345 | break; | 400 | break; |
346 | } | 401 | } |
@@ -723,17 +778,23 @@ class Poche | |||
723 | $purifier = $this->_getPurifier(); | 778 | $purifier = $this->_getPurifier(); |
724 | foreach($items as $item) { | 779 | foreach($items as $item) { |
725 | $url = new Url(base64_encode($item['url'])); | 780 | $url = new Url(base64_encode($item['url'])); |
726 | Tools::logm('Fetching article ' . $item['id']); | 781 | if( $url->isCorrect() ) |
727 | $content = Tools::getPageContent($url); | 782 | { |
728 | $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); | 783 | Tools::logm('Fetching article ' . $item['id']); |
729 | $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); | 784 | $content = Tools::getPageContent($url); |
730 | 785 | $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); | |
731 | // clean content to prevent xss attack | 786 | $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); |
732 | 787 | ||
733 | $title = $purifier->purify($title); | 788 | // clean content to prevent xss attack |
734 | $body = $purifier->purify($body); | 789 | |
735 | $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); | 790 | $title = $purifier->purify($title); |
736 | Tools::logm('Article ' . $item['id'] . ' updated.'); | 791 | $body = $purifier->purify($body); |
792 | $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); | ||
793 | Tools::logm('Article ' . $item['id'] . ' updated.'); | ||
794 | } else | ||
795 | { | ||
796 | Tools::logm('Unvalid URL (' . $item['url'] .') to fetch for article ' . $item['id']); | ||
797 | } | ||
737 | } | 798 | } |
738 | } | 799 | } |
739 | } | 800 | } |
diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 8d6abefd..e9b67771 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php | |||
@@ -33,6 +33,7 @@ class Routing | |||
33 | $this->view = Tools::checkVar('view', 'home'); | 33 | $this->view = Tools::checkVar('view', 'home'); |
34 | $this->action = Tools::checkVar('action'); | 34 | $this->action = Tools::checkVar('action'); |
35 | $this->id = Tools::checkVar('id'); | 35 | $this->id = Tools::checkVar('id'); |
36 | $this->autoclose = Tools::checkVar('autoclose',FALSE); | ||
36 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); | 37 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); |
37 | $this->url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); | 38 | $this->url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); |
38 | } | 39 | } |
@@ -64,7 +65,7 @@ class Routing | |||
64 | $tplVars = array(); | 65 | $tplVars = array(); |
65 | 66 | ||
66 | if (\Session::isLogged()) { | 67 | if (\Session::isLogged()) { |
67 | $this->wallabag->action($this->action, $this->url, $this->id); | 68 | $this->wallabag->action($this->action, $this->url, $this->id, FALSE, $this->autoclose); |
68 | $tplFile = Tools::getTplFile($this->view); | 69 | $tplFile = Tools::getTplFile($this->view); |
69 | $tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id)); | 70 | $tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id)); |
70 | } elseif(ALLOW_REGISTER && isset($_GET['registerform'])) { | 71 | } elseif(ALLOW_REGISTER && isset($_GET['registerform'])) { |
@@ -124,7 +125,7 @@ class Routing | |||
124 | // update password | 125 | // update password |
125 | $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); | 126 | $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); |
126 | } elseif (isset($_GET['newuser'])) { | 127 | } elseif (isset($_GET['newuser'])) { |
127 | $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); | 128 | $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail'], true); |
128 | } elseif (isset($_GET['deluser'])) { | 129 | } elseif (isset($_GET['deluser'])) { |
129 | $this->wallabag->deleteUser($_POST['password4deletinguser']); | 130 | $this->wallabag->deleteUser($_POST['password4deletinguser']); |
130 | } elseif (isset($_GET['epub'])) { | 131 | } elseif (isset($_GET['epub'])) { |
diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index d31939a1..55831571 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php | |||
@@ -202,6 +202,9 @@ class WallabagMobi extends WallabagEBooks | |||
202 | } | 202 | } |
203 | $mobi->setContentProvider($content); | 203 | $mobi->setContentProvider($content); |
204 | 204 | ||
205 | // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9 | ||
206 | $this->bookFileName = preg_replace('/[^A-Za-z0-9\-]/', '', $this->bookFileName); | ||
207 | |||
205 | // we offer file to download | 208 | // we offer file to download |
206 | $mobi->download($this->bookFileName.'.mobi'); | 209 | $mobi->download($this->bookFileName.'.mobi'); |
207 | Tools::logm('Mobi file produced'); | 210 | Tools::logm('Mobi file produced'); |
diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 000faf1c..e569dddd 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php | |||
@@ -46,6 +46,7 @@ | |||
46 | @define ('SHARE_MAIL', TRUE); | 46 | @define ('SHARE_MAIL', TRUE); |
47 | @define ('SHARE_SHAARLI', FALSE); | 47 | @define ('SHARE_SHAARLI', FALSE); |
48 | @define ('SHAARLI_URL', 'http://myshaarliurl.com'); | 48 | @define ('SHAARLI_URL', 'http://myshaarliurl.com'); |
49 | @define ('SHARE_EVERNOTE', FALSE); | ||
49 | @define ('SHARE_DIASPORA', FALSE); | 50 | @define ('SHARE_DIASPORA', FALSE); |
50 | @define ('DIASPORA_URL', 'http://diasporapod.com'); # Don't add a / at the end | 51 | @define ('DIASPORA_URL', 'http://diasporapod.com'); # Don't add a / at the end |
51 | @define ('FLATTR', TRUE); | 52 | @define ('FLATTR', TRUE); |
@@ -60,10 +61,14 @@ | |||
60 | @define ('MOBI', FALSE); | 61 | @define ('MOBI', FALSE); |
61 | @define ('PDF', FALSE); | 62 | @define ('PDF', FALSE); |
62 | 63 | ||
64 | // registration | ||
65 | @define ('SEND_CONFIRMATION_EMAIL', TRUE); // TO BE CHANGED DEPENDING ON POLL | ||
66 | |||
63 | // display or not print link in article view | 67 | // display or not print link in article view |
64 | @define ('SHOW_PRINTLINK', '1'); | 68 | @define ('SHOW_PRINTLINK', '1'); |
65 | // display or not percent of read in article view. Affects only default theme. | 69 | // display or not percent of read in article view. Affects only default theme. |
66 | @define ('SHOW_READPERCENT', '1'); | 70 | @define ('SHOW_READPERCENT', '1'); |
71 | @define ('RELOAD_ARTICLE', TRUE); | ||
67 | @define ('ABS_PATH', 'assets/'); | 72 | @define ('ABS_PATH', 'assets/'); |
68 | 73 | ||
69 | @define ('DEFAULT_THEME', 'baggy'); | 74 | @define ('DEFAULT_THEME', 'baggy'); |