diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-10-12 13:58:35 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-10-12 13:58:35 +0200 |
commit | bc22c9a0acb095970e9494cbe8954f0612e05dc0 (patch) | |
tree | 4e3a94b7469f5b2e3eaf946756235730429bf9d4 /application/NetscapeBookmarkUtils.php | |
parent | 890afc32f744859d11b97eb26ed5c030af9b4145 (diff) | |
parent | ebd67c6e1b40aebdd3a52285ce9ff9412b2a3038 (diff) | |
download | Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.gz Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.zst Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.zip |
Merge tag 'v0.7.0' of github.com:shaarli/Shaarli into stable
Release v0.7.0
Diffstat (limited to 'application/NetscapeBookmarkUtils.php')
-rw-r--r-- | application/NetscapeBookmarkUtils.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php new file mode 100644 index 00000000..fdbb0ad7 --- /dev/null +++ b/application/NetscapeBookmarkUtils.php | |||
@@ -0,0 +1,54 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Utilities to import and export bookmarks using the Netscape format | ||
5 | */ | ||
6 | class NetscapeBookmarkUtils | ||
7 | { | ||
8 | |||
9 | /** | ||
10 | * Filters links and adds Netscape-formatted fields | ||
11 | * | ||
12 | * Added fields: | ||
13 | * - timestamp link addition date, using the Unix epoch format | ||
14 | * - taglist comma-separated tag list | ||
15 | * | ||
16 | * @param LinkDB $linkDb Link datastore | ||
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 | ||
20 | * | ||
21 | * @throws Exception Invalid export selection | ||
22 | * | ||
23 | * @return array The links to be exported, with additional fields | ||
24 | */ | ||
25 | public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl) | ||
26 | { | ||
27 | // see tpl/export.html for possible values | ||
28 | if (! in_array($selection, array('all', 'public', 'private'))) { | ||
29 | throw new Exception('Invalid export selection: "'.$selection.'"'); | ||
30 | } | ||
31 | |||
32 | $bookmarkLinks = array(); | ||
33 | |||
34 | foreach ($linkDb as $link) { | ||
35 | if ($link['private'] != 0 && $selection == 'public') { | ||
36 | continue; | ||
37 | } | ||
38 | if ($link['private'] == 0 && $selection == 'private') { | ||
39 | continue; | ||
40 | } | ||
41 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
42 | $link['timestamp'] = $date->getTimestamp(); | ||
43 | $link['taglist'] = str_replace(' ', ',', $link['tags']); | ||
44 | |||
45 | if (startsWith($link['url'], '?') && $prependNoteUrl) { | ||
46 | $link['url'] = $indexUrl . $link['url']; | ||
47 | } | ||
48 | |||
49 | $bookmarkLinks[] = $link; | ||
50 | } | ||
51 | |||
52 | return $bookmarkLinks; | ||
53 | } | ||
54 | } | ||