X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fapi%2FApiUtils.php;h=f154bb5274a224130e40d4a495dfb1334323a1b0;hb=0a01cefb3bf46abf668cc7fa52bbdf314ed7c234;hp=d024291988db8b7a439e3a0e7986749fa629467a;hpb=c3b00963fe22479e87998c82bc83827a54c8d972;p=github%2Fshaarli%2FShaarli.git diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index d0242919..f154bb52 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php @@ -1,20 +1,18 @@ ! empty($input['title']) ? $input['title'] : $input['url'], + 'url' => $input['url'], + 'description' => ! empty($input['description']) ? $input['description'] : '', + 'tags' => ! empty($input['tags']) ? implode(' ', $input['tags']) : '', + 'private' => $private, + 'created' => new \DateTime(), + ]; + return $link; + } + + /** + * Update link fields using an updated link object. + * + * @param array $oldLink data + * @param array $newLink data + * + * @return array $oldLink updated with $newLink values + */ + public static function updateLink($oldLink, $newLink) + { + foreach (['title', 'url', 'description', 'tags', 'private'] as $field) { + $oldLink[$field] = $newLink[$field]; + } + $oldLink['updated'] = new \DateTime(); + + if (empty($oldLink['url'])) { + $oldLink['url'] = '?' . $oldLink['shorturl']; + } + + if (empty($oldLink['title'])) { + $oldLink['title'] = $oldLink['url']; + } + + return $oldLink; + } }