diff options
Diffstat (limited to 'application/api/ApiUtils.php')
-rw-r--r-- | application/api/ApiUtils.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index a419c396..d4015865 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php | |||
@@ -46,4 +46,35 @@ class ApiUtils | |||
46 | throw new ApiAuthorizationException('Invalid JWT issued time'); | 46 | throw new ApiAuthorizationException('Invalid JWT issued time'); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | |||
50 | /** | ||
51 | * Format a Link for the REST API. | ||
52 | * | ||
53 | * @param array $link Link data read from the datastore. | ||
54 | * @param string $indexUrl Shaarli's index URL (used for relative URL). | ||
55 | * | ||
56 | * @return array Link data formatted for the REST API. | ||
57 | */ | ||
58 | public static function formatLink($link, $indexUrl) | ||
59 | { | ||
60 | $out['id'] = $link['id']; | ||
61 | // Not an internal link | ||
62 | if ($link['url'][0] != '?') { | ||
63 | $out['url'] = $link['url']; | ||
64 | } else { | ||
65 | $out['url'] = $indexUrl . $link['url']; | ||
66 | } | ||
67 | $out['shorturl'] = $link['shorturl']; | ||
68 | $out['title'] = $link['title']; | ||
69 | $out['description'] = $link['description']; | ||
70 | $out['tags'] = preg_split('/\s+/', $link['tags'], -1, PREG_SPLIT_NO_EMPTY); | ||
71 | $out['private'] = $link['private'] == true; | ||
72 | $out['created'] = $link['created']->format(\DateTime::ATOM); | ||
73 | if (! empty($link['updated'])) { | ||
74 | $out['updated'] = $link['updated']->format(\DateTime::ATOM); | ||
75 | } else { | ||
76 | $out['updated'] = ''; | ||
77 | } | ||
78 | return $out; | ||
79 | } | ||
49 | } | 80 | } |