mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-20 21:58:09 +00:00
added Firefox-bookmarks format import mode
This commit is contained in:
parent
9730853564
commit
d31766300a
2 changed files with 48 additions and 15 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue