diff options
-rwxr-xr-x | inc/poche/Poche.class.php | 73 | ||||
-rwxr-xr-x | themes/baggy/config.twig | 2 | ||||
-rwxr-xr-x | themes/default/config.twig | 2 |
3 files changed, 38 insertions, 39 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 |
diff --git a/themes/baggy/config.twig b/themes/baggy/config.twig index 46735f07..e45c3218 100755 --- a/themes/baggy/config.twig +++ b/themes/baggy/config.twig | |||
@@ -111,7 +111,7 @@ | |||
111 | <fieldset class="w500p"> | 111 | <fieldset class="w500p"> |
112 | <div class="row"> | 112 | <div class="row"> |
113 | <label class="col w150p" for="file">{% trans "File:" %}</label> | 113 | <label class="col w150p" for="file">{% trans "File:" %}</label> |
114 | <input class="col" type="file" id="file" name="file" tabindex="4"> | 114 | <input class="col" type="file" id="file" name="file" tabindex="4" required="required"> |
115 | </div> | 115 | </div> |
116 | <div class="row mts txtcenter"> | 116 | <div class="row mts txtcenter"> |
117 | <button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button> | 117 | <button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button> |
diff --git a/themes/default/config.twig b/themes/default/config.twig index 160f6046..8f047ae6 100755 --- a/themes/default/config.twig +++ b/themes/default/config.twig | |||
@@ -110,7 +110,7 @@ | |||
110 | <fieldset class="w500p"> | 110 | <fieldset class="w500p"> |
111 | <div class="row"> | 111 | <div class="row"> |
112 | <label class="col w150p" for="file">{% trans "File:" %}</label> | 112 | <label class="col w150p" for="file">{% trans "File:" %}</label> |
113 | <input class="col" type="file" id="file" name="file" tabindex="4"> | 113 | <input class="col" type="file" id="file" name="file" tabindex="4" required="required"> |
114 | </div> | 114 | </div> |
115 | <div class="row mts txtcenter"> | 115 | <div class="row mts txtcenter"> |
116 | <button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button> | 116 | <button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button> |