aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2015-02-13 19:15:31 +0100
committerThomas Citharel <tcit@tcit.fr>2015-02-13 19:15:31 +0100
commit0eae6d14b8858005919cc3069799f77008a81d29 (patch)
tree9c18566ddada5bf8e391a7fa96f27cfc71471f1b /inc/poche/Poche.class.php
parent1fbef3bfb57b3f73e6817115f10b5876dd0e57ef (diff)
parentdc6ec987585a1c51f678c404143e37b0d844d796 (diff)
downloadwallabag-0eae6d14b8858005919cc3069799f77008a81d29.tar.gz
wallabag-0eae6d14b8858005919cc3069799f77008a81d29.tar.zst
wallabag-0eae6d14b8858005919cc3069799f77008a81d29.zip
Merge branch 'dev' into register
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php95
1 files changed, 78 insertions, 17 deletions
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 }