]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/NetscapeBookmarkUtils.php
4 * Utilities to import and export bookmarks using the Netscape format
6 class NetscapeBookmarkUtils
10 * Filters links and adds Netscape-formatted fields
13 * - timestamp link addition date, using the Unix epoch format
14 * - taglist comma-separated tag list
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
21 * @throws Exception Invalid export selection
23 * @return array The links to be exported, with additional fields
25 public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl)
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.'"');
32 $bookmarkLinks = array();
34 foreach ($linkDb as $link) {
35 if ($link['private'] != 0 && $selection == 'public') {
38 if ($link['private'] == 0 && $selection == 'private') {
41 $date = DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $link['linkdate']);
42 $link['timestamp'] = $date->getTimestamp();
43 $link['taglist'] = str_replace(' ', ',', $link['tags']);
45 if (startsWith($link['url'], '?') && $prependNoteUrl) {
46 $link['url'] = $indexUrl . $link['url'];
49 $bookmarkLinks[] = $link;
52 return $bookmarkLinks;