aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Poche.class.php73
1 files changed, 36 insertions, 37 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 098dd7c1..64a5c4f7 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -551,42 +551,39 @@ class Poche
551 * import datas into your wallabag 551 * import datas into your wallabag
552 * @return boolean 552 * @return boolean
553 */ 553 */
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 554
586 $read = ((sizeof($data) && $read) ? 0 : 1); 555 public function import() {
587 } 556
588 } 557 if ( isset($_FILES['file']) && $_FILES['file']['tmp_name'] ) {
558 Tools::logm('Import stated: parsing file');
559
560 // assume, that file is in json format
561 $str_data = file_get_contents($_FILES['file']['tmp_name']);
562 $data = json_decode($str_data, true);
563
564 if ( $data === null ) {
565 //not json - assume html
566 $html = new simple_html_dom();
567 $html->load_file($_FILES['file']['tmp_name']);
568 $data = array();
569 $read = 0;
570 foreach (array('ol','ul') as $list) {
571 foreach ($html->find($list) as $ul) {
572 foreach ($ul->find('li') as $li) {
573 $tmpEntry = array();
574 $a = $li->find('a');
575 $tmpEntry['url'] = $a[0]->href;
576 $tmpEntry['tags'] = $a[0]->tags;
577 $tmpEntry['is_read'] = $read;
578 if ($tmpEntry['url']) {
579 $data[] = $tmpEntry;
580 }
581 }
582 # the second <ol/ul> is for read links
583 $read = ((sizeof($data) && $read)?0:1);
589 } 584 }
585 }
586 }
590 587
591 // for readability structure 588 // for readability structure
592 589
@@ -629,9 +626,11 @@ class Poche
629 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".')); 626 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".'));
630 } 627 }
631 628
632 Tools::logm('Import of articles finished: ' . $i . ' articles added (w/o content if not provided).'); 629 Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).');
633 } 630 }
634 631 else {
632 $this->messages->add('s', _('Did you forget to select a file?'));
633 }
635 // file parsing finished here 634 // file parsing finished here
636 // now download article contents if any 635 // now download article contents if any
637 // check if we need to download any content 636 // check if we need to download any content