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