aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xinc/poche/Poche.class.php73
-rwxr-xr-xthemes/baggy/config.twig2
-rwxr-xr-xthemes/default/config.twig2
3 files changed, 38 insertions, 39 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
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>