aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php86
1 files changed, 47 insertions, 39 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 098dd7c1..8cebafa3 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -74,12 +74,13 @@ class Poche
74 /** 74 /**
75 * Creates a new user 75 * Creates a new user
76 */ 76 */
77 public function createNewUser($username, $password) 77 public function createNewUser($username, $password, $email = "")
78 { 78 {
79 if (!empty($username) && !empty($password)){ 79 if (!empty($username) && !empty($password)){
80 $newUsername = filter_var($username, FILTER_SANITIZE_STRING); 80 $newUsername = filter_var($username, FILTER_SANITIZE_STRING);
81 $email = filter_var($email, FILTER_SANITIZE_STRING);
81 if (!$this->store->userExists($newUsername)){ 82 if (!$this->store->userExists($newUsername)){
82 if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername))) { 83 if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) {
83 Tools::logm('The new user ' . $newUsername . ' has been installed'); 84 Tools::logm('The new user ' . $newUsername . ' has been installed');
84 $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername)); 85 $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername));
85 Tools::redirect(); 86 Tools::redirect();
@@ -524,6 +525,14 @@ class Poche
524 $longlastingsession = isset($_POST['longlastingsession']); 525 $longlastingsession = isset($_POST['longlastingsession']);
525 $passwordTest = ($isauthenticated) ? $user['password'] : Tools::encodeString($password . $login); 526 $passwordTest = ($isauthenticated) ? $user['password'] : Tools::encodeString($password . $login);
526 Session::login($user['username'], $user['password'], $login, $passwordTest, $longlastingsession, array('poche_user' => new User($user))); 527 Session::login($user['username'], $user['password'], $login, $passwordTest, $longlastingsession, array('poche_user' => new User($user)));
528
529 # reload l10n
530 $language = $user['config']['language'];
531 @putenv('LC_ALL=' . $language);
532 setlocale(LC_ALL, $language);
533 bindtextdomain($language, LOCALE);
534 textdomain($language);
535
527 $this->messages->add('s', _('welcome to your wallabag')); 536 $this->messages->add('s', _('welcome to your wallabag'));
528 Tools::logm('login successful'); 537 Tools::logm('login successful');
529 Tools::redirect($referer); 538 Tools::redirect($referer);
@@ -551,42 +560,39 @@ class Poche
551 * import datas into your wallabag 560 * import datas into your wallabag
552 * @return boolean 561 * @return boolean
553 */ 562 */
554 public function import()
555 {
556 if (isset($_FILES['file'])) {
557 Tools::logm('Import stated: parsing file');
558
559 // assume, that file is in json format
560
561 $str_data = file_get_contents($_FILES['file']['tmp_name']);
562 $data = json_decode($str_data, true);
563 if ($data === null) {
564
565 // not json - assume html
566
567 $html = new simple_html_dom();
568 $html->load_file($_FILES['file']['tmp_name']);
569 $data = array();
570 $read = 0;
571 foreach(array('ol','ul') as $list) {
572 foreach($html->find($list) as $ul) {
573 foreach($ul->find('li') as $li) {
574 $tmpEntry = array();
575 $a = $li->find('a');
576 $tmpEntry['url'] = $a[0]->href;
577 $tmpEntry['tags'] = $a[0]->tags;
578 $tmpEntry['is_read'] = $read;
579 if ($tmpEntry['url']) {
580 $data[] = $tmpEntry;
581 }
582 }
583
584 // the second <ol/ul> is for read links
585 563
586 $read = ((sizeof($data) && $read) ? 0 : 1); 564 public function import() {
587 } 565
588 } 566 if ( isset($_FILES['file']) && $_FILES['file']['tmp_name'] ) {
567 Tools::logm('Import stated: parsing file');
568
569 // assume, that file is in json format
570 $str_data = file_get_contents($_FILES['file']['tmp_name']);
571 $data = json_decode($str_data, true);
572
573 if ( $data === null ) {
574 //not json - assume html
575 $html = new simple_html_dom();
576 $html->load_file($_FILES['file']['tmp_name']);
577 $data = array();
578 $read = 0;
579 foreach (array('ol','ul') as $list) {
580 foreach ($html->find($list) as $ul) {
581 foreach ($ul->find('li') as $li) {
582 $tmpEntry = array();
583 $a = $li->find('a');
584 $tmpEntry['url'] = $a[0]->href;
585 $tmpEntry['tags'] = $a[0]->tags;
586 $tmpEntry['is_read'] = $read;
587 if ($tmpEntry['url']) {
588 $data[] = $tmpEntry;
589 }
590 }
591 # the second <ol/ul> is for read links
592 $read = ((sizeof($data) && $read)?0:1);
589 } 593 }
594 }
595 }
590 596
591 // for readability structure 597 // for readability structure
592 598
@@ -629,9 +635,11 @@ class Poche
629 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".')); 635 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".'));
630 } 636 }
631 637
632 Tools::logm('Import of articles finished: ' . $i . ' articles added (w/o content if not provided).'); 638 Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).');
633 } 639 }
634 640 else {
641 $this->messages->add('s', _('Did you forget to select a file?'));
642 }
635 // file parsing finished here 643 // file parsing finished here
636 // now download article contents if any 644 // now download article contents if any
637 // check if we need to download any content 645 // check if we need to download any content