]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/NetscapeBookmarkUtils.php
Merge pull request #532 from ArthurHoaro/hotfix/title-retrieve-the-return
[github/shaarli/Shaarli.git] / application / NetscapeBookmarkUtils.php
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 The link datastore
17 * @param string $selection Which links to export: (all|private|public)
18 *
19 * @throws Exception Invalid export selection
20 *
21 * @return array The links to be exported, with additional fields
22 */
23 public static function filterAndFormat($linkDb, $selection)
24 {
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.'"');
28 }
29
30 $bookmarkLinks = array();
31
32 foreach ($linkDb as $link) {
33 if ($link['private'] != 0 && $selection == 'public') {
34 continue;
35 }
36 if ($link['private'] == 0 && $selection == 'private') {
37 continue;
38 }
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;
43 }
44
45 return $bookmarkLinks;
46 }
47 }