aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2019-07-27 10:56:57 +0200
committerArthurHoaro <arthur@hoa.ro>2019-07-27 11:46:05 +0200
commit81cae5f5dd4a7cbd15e897572396a5d7a3e659fe (patch)
tree9f8fdee4f67732eb8065734fa9e38dbd3e35c884
parent37686457f024cf088e5def164e1aa3539e3de01d (diff)
downloadShaarli-81cae5f5dd4a7cbd15e897572396a5d7a3e659fe.tar.gz
Shaarli-81cae5f5dd4a7cbd15e897572396a5d7a3e659fe.tar.zst
Shaarli-81cae5f5dd4a7cbd15e897572396a5d7a3e659fe.zip
Persist sticky status on bookmark update
Fixes #1331
-rw-r--r--index.php24
1 files changed, 10 insertions, 14 deletions
diff --git a/index.php b/index.php
index f0f71dbb..9e473936 100644
--- a/index.php
+++ b/index.php
@@ -1126,22 +1126,24 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1126 1126
1127 // lf_id should only be present if the link exists. 1127 // lf_id should only be present if the link exists.
1128 $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId(); 1128 $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId();
1129 $link['id'] = $id;
1129 // Linkdate is kept here to: 1130 // Linkdate is kept here to:
1130 // - use the same permalink for notes as they're displayed when creating them 1131 // - use the same permalink for notes as they're displayed when creating them
1131 // - let users hack creation date of their posts 1132 // - let users hack creation date of their posts
1132 // See: https://shaarli.readthedocs.io/en/master/guides/various-hacks/#changing-the-timestamp-for-a-shaare 1133 // See: https://shaarli.readthedocs.io/en/master/guides/various-hacks/#changing-the-timestamp-for-a-shaare
1133 $linkdate = escape($_POST['lf_linkdate']); 1134 $linkdate = escape($_POST['lf_linkdate']);
1135 $link['created'] = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
1134 if (isset($LINKSDB[$id])) { 1136 if (isset($LINKSDB[$id])) {
1135 // Edit 1137 // Edit
1136 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); 1138 $link['updated'] = new DateTime();
1137 $updated = new DateTime(); 1139 $link['shorturl'] = $LINKSDB[$id]['shorturl'];
1138 $shortUrl = $LINKSDB[$id]['shorturl']; 1140 $link['sticky'] = isset($LINKSDB[$id]['sticky']) ? $LINKSDB[$id]['sticky'] : false;
1139 $new = false; 1141 $new = false;
1140 } else { 1142 } else {
1141 // New link 1143 // New link
1142 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); 1144 $link['updated'] = null;
1143 $updated = null; 1145 $link['shorturl'] = link_small_hash($link['created'], $id);
1144 $shortUrl = link_small_hash($created, $id); 1146 $link['sticky'] = false;
1145 $new = true; 1147 $new = true;
1146 } 1148 }
1147 1149
@@ -1157,17 +1159,13 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1157 } 1159 }
1158 $url = whitelist_protocols(trim($_POST['lf_url']), $conf->get('security.allowed_protocols')); 1160 $url = whitelist_protocols(trim($_POST['lf_url']), $conf->get('security.allowed_protocols'));
1159 1161
1160 $link = array( 1162 $link = array_merge($link, [
1161 'id' => $id,
1162 'title' => trim($_POST['lf_title']), 1163 'title' => trim($_POST['lf_title']),
1163 'url' => $url, 1164 'url' => $url,
1164 'description' => $_POST['lf_description'], 1165 'description' => $_POST['lf_description'],
1165 'private' => (isset($_POST['lf_private']) ? 1 : 0), 1166 'private' => (isset($_POST['lf_private']) ? 1 : 0),
1166 'created' => $created,
1167 'updated' => $updated,
1168 'tags' => str_replace(',', ' ', $tags), 1167 'tags' => str_replace(',', ' ', $tags),
1169 'shorturl' => $shortUrl, 1168 ]);
1170 );
1171 1169
1172 // If title is empty, use the URL as title. 1170 // If title is empty, use the URL as title.
1173 if ($link['title'] == '') { 1171 if ($link['title'] == '') {
@@ -1181,8 +1179,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1181 $link['thumbnail'] = $thumbnailer->get($url); 1179 $link['thumbnail'] = $thumbnailer->get($url);
1182 } 1180 }
1183 1181
1184 $link['sticky'] = isset($link['sticky']) ? $link['sticky'] : false;
1185
1186 $pluginManager->executeHooks('save_link', $link); 1182 $pluginManager->executeHooks('save_link', $link);
1187 1183
1188 $LINKSDB[$id] = $link; 1184 $LINKSDB[$id] = $link;