From 2c8394027020a297ea435d36c30b4c63981cf473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 19 May 2015 21:11:19 +0200 Subject: fix restart of import --- inc/poche/Routing.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 138da48d..33a81435 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -141,7 +141,7 @@ class Routing $pdf->producePDF(); } elseif (isset($_GET['import'])) { $import = $this->wallabag->import(); - $tplVars = array_merge($this->vars, $import); + $this->vars = array_merge($this->vars, $import); } elseif (isset($_GET['empty-cache'])) { Tools::emptyCache(); } elseif (isset($_GET['export'])) { -- cgit v1.2.3 From d31766300a4c15acf0d6d496eb0156f2e6d3a269 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 22 May 2015 19:29:12 +0200 Subject: added Firefox-bookmarks format import mode --- inc/poche/Poche.class.php | 52 +++++++++++++++++++++++++++++++++-------------- inc/poche/Tools.class.php | 11 ++++++++++ 2 files changed, 48 insertions(+), 15 deletions(-) (limited to 'inc/poche') 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 $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
    is for read links - $read = ((sizeof($data) && $read)?0:1); + # the second
      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
        is for read links + $read = ((sizeof($data) && $read)?0:1); + } + } + } + } // for readability structure 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 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; + } + } -- cgit v1.2.3 From f0a819a968e5d935c757bb65acdfbca480398274 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 22 May 2015 20:09:23 +0200 Subject: added commentsand fixed something forgotten --- inc/poche/Poche.class.php | 2 +- inc/poche/Tools.class.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 7b13c97e..d039de1f 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -733,7 +733,7 @@ class Poche $data = array(); $read = 0; - if (Tools:: get_doctype($html)) { + if (Tools::get_doctype($html)->innertext == "") { // Firefox-bookmarks HTML foreach (array('DL','ul') as $list) { foreach ($html->find($list) as $ul) { diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1c554590..f34e8beb 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -420,6 +420,14 @@ final class Tools return str_replace('+', '', $token); } + /** + * + * Returns the doctype for an HTML document (used for Mozilla Bookmarks) + * @param simple_html_dom $doc + * @return doctype $el + * + */ + function get_doctype($doc) { $els = $doc->find('unknown'); -- cgit v1.2.3 From 3a690fad55cafb5b30debd1f3069e9c87b0a4b39 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 25 May 2015 20:44:22 +0200 Subject: declare function correctly --- inc/poche/Tools.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index f34e8beb..f3d1013f 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -428,7 +428,7 @@ final class Tools * */ - function get_doctype($doc) + public static function get_doctype($doc) { $els = $doc->find('unknown'); -- cgit v1.2.3 From ddbb2308a3302e2d2d6ff89f4dd3235f85d335e1 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 30 May 2015 18:11:00 +0200 Subject: check that URL are real ones before importing them (for instance, avoid bookmarklets) --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index d039de1f..4fb028ff 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -788,7 +788,7 @@ class Poche $urlsInserted = array(); //urls of articles inserted foreach($data as $record) { $url = trim(isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '')); - if ($url and !in_array($url, $urlsInserted)) { + if (filter_var($url, FILTER_VALIDATE_URL) and !in_array($url, $urlsInserted)) { $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ') . ' ' . _('click to finish import') . ''); $body = (isset($record['content']) ? $record['content'] : ''); $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive']) ? intval($record['archive']) : 0)); -- cgit v1.2.3