aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2015-05-22 19:29:12 +0200
committerThomas Citharel <tcit@tcit.fr>2015-05-22 19:29:12 +0200
commitd31766300a4c15acf0d6d496eb0156f2e6d3a269 (patch)
treed4cdcaaeee1214fcf51a6203a0adc912741846a0
parent973085356452b3d74147a5e768907924029be331 (diff)
downloadwallabag-d31766300a4c15acf0d6d496eb0156f2e6d3a269.tar.gz
wallabag-d31766300a4c15acf0d6d496eb0156f2e6d3a269.tar.zst
wallabag-d31766300a4c15acf0d6d496eb0156f2e6d3a269.zip
added Firefox-bookmarks format import mode
-rwxr-xr-xinc/poche/Poche.class.php52
-rwxr-xr-xinc/poche/Tools.class.php11
2 files changed, 48 insertions, 15 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 465d9f95..7b13c97e 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -732,23 +732,45 @@ class Poche
732 $html->load_file($_FILES['file']['tmp_name']); 732 $html->load_file($_FILES['file']['tmp_name']);
733 $data = array(); 733 $data = array();
734 $read = 0; 734 $read = 0;
735 foreach (array('ol','ul') as $list) { 735
736 foreach ($html->find($list) as $ul) { 736 if (Tools:: get_doctype($html)) {
737 foreach ($ul->find('li') as $li) { 737 // Firefox-bookmarks HTML
738 $tmpEntry = array(); 738 foreach (array('DL','ul') as $list) {
739 $a = $li->find('a'); 739 foreach ($html->find($list) as $ul) {
740 $tmpEntry['url'] = $a[0]->href; 740 foreach ($ul->find('DT') as $li) {
741 $tmpEntry['tags'] = $a[0]->tags; 741 $tmpEntry = array();
742 $tmpEntry['is_read'] = $read; 742 $a = $li->find('A');
743 if ($tmpEntry['url']) { 743 $tmpEntry['url'] = $a[0]->href;
744 $data[] = $tmpEntry; 744 $tmpEntry['tags'] = $a[0]->tags;
745 $tmpEntry['is_read'] = $read;
746 if ($tmpEntry['url']) {
747 $data[] = $tmpEntry;
748 }
745 } 749 }
746 } 750 # the second <ol/ul> is for read links
747 # the second <ol/ul> is for read links 751 $read = ((sizeof($data) && $read)?0:1);
748 $read = ((sizeof($data) && $read)?0:1); 752 }
749 } 753 }
750 } 754 } else {
751 } 755 // regular HTML
756 foreach (array('ol','ul') as $list) {
757 foreach ($html->find($list) as $ul) {
758 foreach ($ul->find('li') as $li) {
759 $tmpEntry = array();
760 $a = $li->find('a');
761 $tmpEntry['url'] = $a[0]->href;
762 $tmpEntry['tags'] = $a[0]->tags;
763 $tmpEntry['is_read'] = $read;
764 if ($tmpEntry['url']) {
765 $data[] = $tmpEntry;
766 }
767 }
768 # the second <ol/ul> is for read links
769 $read = ((sizeof($data) && $read)?0:1);
770 }
771 }
772 }
773 }
752 774
753 // for readability structure 775 // for readability structure
754 776
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index c8fb2e52..1c554590 100755
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -420,4 +420,15 @@ final class Tools
420 return str_replace('+', '', $token); 420 return str_replace('+', '', $token);
421 } 421 }
422 422
423 function get_doctype($doc)
424 {
425 $els = $doc->find('unknown');
426
427 foreach ($els as $e => $el)
428 if ($el->parent()->tag == 'root')
429 return $el;
430
431 return NULL;
432 }
433
423} 434}