aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/api/ApiUtils.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/api/ApiUtils.php')
-rw-r--r--application/api/ApiUtils.php21
1 files changed, 17 insertions, 4 deletions
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php
index 05a2840a..9228bb2d 100644
--- a/application/api/ApiUtils.php
+++ b/application/api/ApiUtils.php
@@ -91,13 +91,17 @@ class ApiUtils
91 * If no URL is provided, it will generate a local note URL. 91 * If no URL is provided, it will generate a local note URL.
92 * If no title is provided, it will use the URL as title. 92 * If no title is provided, it will use the URL as title.
93 * 93 *
94 * @param array|null $input Request Link. 94 * @param array|null $input Request Link.
95 * @param bool $defaultPrivate Setting defined if a bookmark is private by default. 95 * @param bool $defaultPrivate Setting defined if a bookmark is private by default.
96 * @param string $tagsSeparator Tags separator loaded from the config file.
96 * 97 *
97 * @return Bookmark instance. 98 * @return Bookmark instance.
98 */ 99 */
99 public static function buildBookmarkFromRequest(?array $input, bool $defaultPrivate): Bookmark 100 public static function buildBookmarkFromRequest(
100 { 101 ?array $input,
102 bool $defaultPrivate,
103 string $tagsSeparator
104 ): Bookmark {
101 $bookmark = new Bookmark(); 105 $bookmark = new Bookmark();
102 $url = ! empty($input['url']) ? cleanup_url($input['url']) : ''; 106 $url = ! empty($input['url']) ? cleanup_url($input['url']) : '';
103 if (isset($input['private'])) { 107 if (isset($input['private'])) {
@@ -109,6 +113,15 @@ class ApiUtils
109 $bookmark->setTitle(! empty($input['title']) ? $input['title'] : ''); 113 $bookmark->setTitle(! empty($input['title']) ? $input['title'] : '');
110 $bookmark->setUrl($url); 114 $bookmark->setUrl($url);
111 $bookmark->setDescription(! empty($input['description']) ? $input['description'] : ''); 115 $bookmark->setDescription(! empty($input['description']) ? $input['description'] : '');
116
117 // Be permissive with provided tags format
118 if (is_string($input['tags'] ?? null)) {
119 $input['tags'] = tags_str2array($input['tags'], $tagsSeparator);
120 }
121 if (is_array($input['tags'] ?? null) && count($input['tags']) === 1 && is_string($input['tags'][0])) {
122 $input['tags'] = tags_str2array($input['tags'][0], $tagsSeparator);
123 }
124
112 $bookmark->setTags(! empty($input['tags']) ? $input['tags'] : []); 125 $bookmark->setTags(! empty($input['tags']) ? $input['tags'] : []);
113 $bookmark->setPrivate($private); 126 $bookmark->setPrivate($private);
114 127