]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
added Firefox-bookmarks format import mode
authorThomas Citharel <tcit@tcit.fr>
Fri, 22 May 2015 17:29:12 +0000 (19:29 +0200)
committerThomas Citharel <tcit@tcit.fr>
Fri, 22 May 2015 17:29:12 +0000 (19:29 +0200)
inc/poche/Poche.class.php
inc/poche/Tools.class.php

index 465d9f956408da5ab39e2f8275716845f78d53d1..7b13c97e4b2d4dd0780a89c9bf679c91388a3cb1 100755 (executable)
@@ -732,23 +732,45 @@ class Poche
           $html->load_file($_FILES['file']['tmp_name']);
           $data = array();
           $read = 0;
-          foreach (array('ol','ul') as $list) {
-            foreach ($html->find($list) as $ul) {
-              foreach ($ul->find('li') as $li) {
-                $tmpEntry = array();
-                  $a = $li->find('a');
-                  $tmpEntry['url'] = $a[0]->href;
-                  $tmpEntry['tags'] = $a[0]->tags;
-                  $tmpEntry['is_read'] = $read;
-                  if ($tmpEntry['url']) {
-                    $data[] = $tmpEntry;
+
+          if (Tools:: get_doctype($html)) {
+            // Firefox-bookmarks HTML
+            foreach (array('DL','ul') as $list) {
+                foreach ($html->find($list) as $ul) {
+                  foreach ($ul->find('DT') as $li) {
+                    $tmpEntry = array();
+                      $a = $li->find('A');
+                      $tmpEntry['url'] = $a[0]->href;
+                      $tmpEntry['tags'] = $a[0]->tags;
+                      $tmpEntry['is_read'] = $read;
+                      if ($tmpEntry['url']) {
+                        $data[] = $tmpEntry;
+                      }
                   }
-              }
-              # the second <ol/ul> is for read links
-              $read = ((sizeof($data) && $read)?0:1);
+                  # the second <ol/ul> is for read links
+                  $read = ((sizeof($data) && $read)?0:1);
+                }
             }
-          }
-       }
+          } else {
+            // regular HTML
+            foreach (array('ol','ul') as $list) {
+                foreach ($html->find($list) as $ul) {
+                  foreach ($ul->find('li') as $li) {
+                    $tmpEntry = array();
+                      $a = $li->find('a');
+                      $tmpEntry['url'] = $a[0]->href;
+                      $tmpEntry['tags'] = $a[0]->tags;
+                      $tmpEntry['is_read'] = $read;
+                      if ($tmpEntry['url']) {
+                        $data[] = $tmpEntry;
+                      }
+                  }
+                  # the second <ol/ul> is for read links
+                  $read = ((sizeof($data) && $read)?0:1);
+                }
+              }
+               }
+        }
 
             // for readability structure
 
index c8fb2e527ba2dfbba6b4d391cc69d864234ba76b..1c55459082c439cd0a1bf77644bccac135337fa2 100755 (executable)
@@ -420,4 +420,15 @@ final class Tools
         return str_replace('+', '', $token);
     }
 
+    function get_doctype($doc)
+    {
+        $els = $doc->find('unknown');
+
+        foreach ($els as $e => $el) 
+            if ($el->parent()->tag == 'root') 
+                return $el;
+
+        return NULL;
+    }
+
 }