+
+ // lf_id should only be present if the link exists.
+ $id = !empty($_POST['lf_id']) ? (int) escape($_POST['lf_id']) : $LINKSDB->getNextId();
+ // Linkdate is kept here to:
+ // - use the same permalink for notes as they're displayed when creating them
+ // - let users hack creation date of their posts
+ // See: https://github.com/shaarli/Shaarli/wiki/Datastore-hacks#changing-the-timestamp-for-a-link
+ $linkdate = escape($_POST['lf_linkdate']);
+ if (isset($LINKSDB[$id])) {
+ // Edit
+ $created = DateTime::createFromFormat('Ymd_His', $linkdate);
+ $updated = new DateTime();
+ } else {
+ // New link
+ $created = DateTime::createFromFormat('Ymd_His', $linkdate);
+ $updated = null;
+ }
+