Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist sticky status on bookmark update #1333

Merged
merged 1 commit into from
Jul 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1126,22 +1126,24 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,

// lf_id should only be present if the link exists.
$id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId();
$link['id'] = $id;
// 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://shaarli.readthedocs.io/en/master/guides/various-hacks/#changing-the-timestamp-for-a-shaare
$linkdate = escape($_POST['lf_linkdate']);
$link['created'] = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
if (isset($LINKSDB[$id])) {
// Edit
$created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
$updated = new DateTime();
$shortUrl = $LINKSDB[$id]['shorturl'];
$link['updated'] = new DateTime();
$link['shorturl'] = $LINKSDB[$id]['shorturl'];
$link['sticky'] = isset($LINKSDB[$id]['sticky']) ? $LINKSDB[$id]['sticky'] : false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the shorthand $link['sticky'] = $LINKSDB[$id]['sticky'] ?? false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, Shaarli v0.10.x still supports PHP 5.6 (support which will be dropped in the next release o/).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I didn't know that. Good point.

$new = false;
} else {
// New link
$created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
$updated = null;
$shortUrl = link_small_hash($created, $id);
$link['updated'] = null;
$link['shorturl'] = link_small_hash($link['created'], $id);
$link['sticky'] = false;
$new = true;
}

Expand All @@ -1157,17 +1159,13 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
}
$url = whitelist_protocols(trim($_POST['lf_url']), $conf->get('security.allowed_protocols'));

$link = array(
'id' => $id,
$link = array_merge($link, [
'title' => trim($_POST['lf_title']),
'url' => $url,
'description' => $_POST['lf_description'],
'private' => (isset($_POST['lf_private']) ? 1 : 0),
'created' => $created,
'updated' => $updated,
'tags' => str_replace(',', ' ', $tags),
'shorturl' => $shortUrl,
);
]);

// If title is empty, use the URL as title.
if ($link['title'] == '') {
Expand All @@ -1181,8 +1179,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
$link['thumbnail'] = $thumbnailer->get($url);
}

$link['sticky'] = isset($link['sticky']) ? $link['sticky'] : false;

$pluginManager->executeHooks('save_link', $link);

$LINKSDB[$id] = $link;
Expand Down