]>
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 The link datastore
17 * @param string $selection Which links to export: (all|private|public)
19 * @throws Exception Invalid export selection
21 * @return array The links to be exported, with additional fields
23 public static function filterAndFormat($linkDb, $selection)
25 // see tpl/export.html for possible values
26 if (! in_array($selection, array('all','public','private'))) {
27 throw new Exception('Invalid export selection: "'.$selection.'"');
30 $bookmarkLinks = array();
32 foreach ($linkDb as $link) {
33 if ($link['private'] != 0 && $selection == 'public') {
36 if ($link['private'] == 0 && $selection == 'private') {
39 $date = DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $link['linkdate']);
40 $link['timestamp'] = $date->getTimestamp();
41 $link['taglist'] = str_replace(' ', ',', $link['tags']);
42 $bookmarkLinks[] = $link;
45 return $bookmarkLinks;