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.php73
1 files changed, 36 insertions, 37 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 3e9c2991..c80e5d2a 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -559,42 +559,39 @@ class Poche
559 * import datas into your wallabag 559 * import datas into your wallabag
560 * @return boolean 560 * @return boolean
561 */ 561 */
562 public function import()
563 {
564 if (isset($_FILES['file'])) {
565 Tools::logm('Import stated: parsing file');
566
567 // assume, that file is in json format
568
569 $str_data = file_get_contents($_FILES['file']['tmp_name']);
570 $data = json_decode($str_data, true);
571 if ($data === null) {
572
573 // not json - assume html
574
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
592 // the second <ol/ul> is for read links
593 562
594 $read = ((sizeof($data) && $read) ? 0 : 1); 563 public function import() {
595 } 564
596 } 565 if ( isset($_FILES['file']) && $_FILES['file']['tmp_name'] ) {
566 Tools::logm('Import stated: parsing file');
567
568 // assume, that file is in json format
569 $str_data = file_get_contents($_FILES['file']['tmp_name']);
570 $data = json_decode($str_data, true);
571
572 if ( $data === null ) {
573 //not json - assume html
574 $html = new simple_html_dom();
575 $html->load_file($_FILES['file']['tmp_name']);
576 $data = array();
577 $read = 0;
578 foreach (array('ol','ul') as $list) {
579 foreach ($html->find($list) as $ul) {
580 foreach ($ul->find('li') as $li) {
581 $tmpEntry = array();
582 $a = $li->find('a');
583 $tmpEntry['url'] = $a[0]->href;
584 $tmpEntry['tags'] = $a[0]->tags;
585 $tmpEntry['is_read'] = $read;
586 if ($tmpEntry['url']) {
587 $data[] = $tmpEntry;
588 }
589 }
590 # the second <ol/ul> is for read links
591 $read = ((sizeof($data) && $read)?0:1);
597 } 592 }
593 }
594 }
598 595
599 // for readability structure 596 // for readability structure
600 597
@@ -637,9 +634,11 @@ class Poche
637 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".')); 634 $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".'));
638 } 635 }
639 636
640 Tools::logm('Import of articles finished: ' . $i . ' articles added (w/o content if not provided).'); 637 Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).');
641 } 638 }
642 639 else {
640 $this->messages->add('s', _('Did you forget to select a file?'));
641 }
643 // file parsing finished here 642 // file parsing finished here
644 // now download article contents if any 643 // now download article contents if any
645 // check if we need to download any content 644 // check if we need to download any content