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.php96
1 files changed, 53 insertions, 43 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index a49413f2..27d6f4a6 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();
@@ -313,6 +314,8 @@ class Poche
313 314
314 switch ($view) 315 switch ($view)
315 { 316 {
317 case 'about':
318 break;
316 case 'config': 319 case 'config':
317 $dev_infos = $this->_getPocheVersion('dev'); 320 $dev_infos = $this->_getPocheVersion('dev');
318 $dev = trim($dev_infos[0]); 321 $dev = trim($dev_infos[0]);
@@ -387,7 +390,7 @@ class Poche
387 $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' )); 390 $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' ));
388 $tpl_vars['page_links'] = $page_links; 391 $tpl_vars['page_links'] = $page_links;
389 $tpl_vars['nb_results'] = $count; 392 $tpl_vars['nb_results'] = $count;
390 $tpl_vars['search_term'] = $search; 393 $tpl_vars['searchterm'] = $search;
391 } 394 }
392 break; 395 break;
393 case 'view': 396 case 'view':
@@ -524,6 +527,14 @@ class Poche
524 $longlastingsession = isset($_POST['longlastingsession']); 527 $longlastingsession = isset($_POST['longlastingsession']);
525 $passwordTest = ($isauthenticated) ? $user['password'] : Tools::encodeString($password . $login); 528 $passwordTest = ($isauthenticated) ? $user['password'] : Tools::encodeString($password . $login);
526 Session::login($user['username'], $user['password'], $login, $passwordTest, $longlastingsession, array('poche_user' => new User($user))); 529 Session::login($user['username'], $user['password'], $login, $passwordTest, $longlastingsession, array('poche_user' => new User($user)));
530
531 # reload l10n
532 $language = $user['config']['language'];
533 @putenv('LC_ALL=' . $language);
534 setlocale(LC_ALL, $language);
535 bindtextdomain($language, LOCALE);
536 textdomain($language);
537
527 $this->messages->add('s', _('welcome to your wallabag')); 538 $this->messages->add('s', _('welcome to your wallabag'));
528 Tools::logm('login successful'); 539 Tools::logm('login successful');
529 Tools::redirect($referer); 540 Tools::redirect($referer);
@@ -551,42 +562,39 @@ class Poche
551 * import datas into your wallabag 562 * import datas into your wallabag
552 * @return boolean 563 * @return boolean
553 */ 564 */
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 565
586 $read = ((sizeof($data) && $read) ? 0 : 1); 566 public function import() {
587 } 567
588 } 568 if ( isset($_FILES['file']) && $_FILES['file']['tmp_name'] ) {
569 Tools::logm('Import stated: parsing file');
570
571 // assume, that file is in json format
572 $str_data = file_get_contents($_FILES['file']['tmp_name']);
573 $data = json_decode($str_data, true);
574
575 if ( $data === null ) {
576 //not json - assume html
577 $html = new simple_html_dom();
578 $html->load_file($_FILES['file']['tmp_name']);
579 $data = array();
580 $read = 0;
581 foreach (array('ol','ul') as $list) {
582 foreach ($html->find($list) as $ul) {
583 foreach ($ul->find('li') as $li) {
584 $tmpEntry = array();
585 $a = $li->find('a');
586 $tmpEntry['url'] = $a[0]->href;
587 $tmpEntry['tags'] = $a[0]->tags;
588 $tmpEntry['is_read'] = $read;
589 if ($tmpEntry['url']) {
590 $data[] = $tmpEntry;
591 }
592 }
593 # the second <ol/ul> is for read links
594 $read = ((sizeof($data) && $read)?0:1);
589 } 595 }
596 }
597 }
590 598
591 // for readability structure 599 // for readability structure
592 600
@@ -629,9 +637,11 @@ class Poche
629 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".')); 637 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".'));
630 } 638 }
631 639
632 Tools::logm('Import of articles finished: ' . $i . ' articles added (w/o content if not provided).'); 640 Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).');
633 } 641 }
634 642 else {
643 $this->messages->add('s', _('Did you forget to select a file?'));
644 }
635 // file parsing finished here 645 // file parsing finished here
636 // now download article contents if any 646 // now download article contents if any
637 // check if we need to download any content 647 // check if we need to download any content
@@ -750,8 +760,8 @@ class Poche
750 die(sprintf(_('User with this id (%d) does not exist.'), $user_id)); 760 die(sprintf(_('User with this id (%d) does not exist.'), $user_id));
751 } 761 }
752 762
753 if (!in_array($type, $allowed_types) || $token != $config['token']) { 763 if (!in_array($type, $allowed_types) || !isset($config['token']) || $token != $config['token']) {
754 die(_('Uh, there is a problem while generating feeds.')); 764 die(_('Uh, there is a problem while generating feed. Wrong token used?'));
755 } 765 }
756 766
757 $feed = new FeedWriter(RSS2); 767 $feed = new FeedWriter(RSS2);
@@ -802,4 +812,4 @@ class Poche
802 } 812 }
803 813
804 814
805} 815} \ No newline at end of file