diff options
author | VirtualTam <virtualtam@flibidi.net> | 2016-05-05 19:22:06 +0200 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2016-05-06 16:12:46 +0200 |
commit | bb4a23aa863b63e6148a085c15dedd7c960b4206 (patch) | |
tree | d4a484ca0eef729f5c02d95e0b20cc40e120853a /application/NetscapeBookmarkUtils.php | |
parent | 6275a65969a84a360588e0a62b025963e9ec98e0 (diff) | |
download | Shaarli-bb4a23aa863b63e6148a085c15dedd7c960b4206.tar.gz Shaarli-bb4a23aa863b63e6148a085c15dedd7c960b4206.tar.zst Shaarli-bb4a23aa863b63e6148a085c15dedd7c960b4206.zip |
Export: allow prepending notes with the Shaarli instance's URL
Relates to #102
Additions:
- application:
- export: allow prepending note permalinks with the instance's URL
- test coverage
Modifications:
- export template: switch to an HTML form
- link selection (all/private/public)
- prepend note permalinks with the instance's URL
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'application/NetscapeBookmarkUtils.php')
-rw-r--r-- | application/NetscapeBookmarkUtils.php | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index 8a296705..fdbb0ad7 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php | |||
@@ -13,17 +13,19 @@ class NetscapeBookmarkUtils | |||
13 | * - timestamp link addition date, using the Unix epoch format | 13 | * - timestamp link addition date, using the Unix epoch format |
14 | * - taglist comma-separated tag list | 14 | * - taglist comma-separated tag list |
15 | * | 15 | * |
16 | * @param LinkDB $linkDb The link datastore | 16 | * @param LinkDB $linkDb Link datastore |
17 | * @param string $selection Which links to export: (all|private|public) | 17 | * @param string $selection Which links to export: (all|private|public) |
18 | * @param bool $prependNoteUrl Prepend note permalinks with the server's URL | ||
19 | * @param string $indexUrl Absolute URL of the Shaarli index page | ||
18 | * | 20 | * |
19 | * @throws Exception Invalid export selection | 21 | * @throws Exception Invalid export selection |
20 | * | 22 | * |
21 | * @return array The links to be exported, with additional fields | 23 | * @return array The links to be exported, with additional fields |
22 | */ | 24 | */ |
23 | public static function filterAndFormat($linkDb, $selection) | 25 | public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl) |
24 | { | 26 | { |
25 | // see tpl/export.html for possible values | 27 | // see tpl/export.html for possible values |
26 | if (! in_array($selection, array('all','public','private'))) { | 28 | if (! in_array($selection, array('all', 'public', 'private'))) { |
27 | throw new Exception('Invalid export selection: "'.$selection.'"'); | 29 | throw new Exception('Invalid export selection: "'.$selection.'"'); |
28 | } | 30 | } |
29 | 31 | ||
@@ -39,6 +41,11 @@ class NetscapeBookmarkUtils | |||
39 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | 41 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); |
40 | $link['timestamp'] = $date->getTimestamp(); | 42 | $link['timestamp'] = $date->getTimestamp(); |
41 | $link['taglist'] = str_replace(' ', ',', $link['tags']); | 43 | $link['taglist'] = str_replace(' ', ',', $link['tags']); |
44 | |||
45 | if (startsWith($link['url'], '?') && $prependNoteUrl) { | ||
46 | $link['url'] = $indexUrl . $link['url']; | ||
47 | } | ||
48 | |||
42 | $bookmarkLinks[] = $link; | 49 | $bookmarkLinks[] = $link; |
43 | } | 50 | } |
44 | 51 | ||