public static $PAGE_DELETELINK = 'delete_link';
+ public static $PAGE_CHANGE_VISIBILITY = 'change_visibility';
+
public static $PAGE_PINLINK = 'pin';
public static $PAGE_EXPORT = 'export';
return self::$PAGE_DELETELINK;
}
+ if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) {
+ return self::$PAGE_CHANGE_VISIBILITY;
+ }
+
if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
return self::$PAGE_PINLINK;
}
});
}
+ const changeVisibilityButtons = document.querySelectorAll('.actions-change-visibility');
+ if (changeVisibilityButtons != null && token != null) {
+ [...changeVisibilityButtons].forEach((button) => {
+ button.addEventListener('click', (event) => {
+ event.preventDefault();
+ const visibility = event.target.getAttribute('data-visibility');
+
+ const links = [];
+ const linkCheckedCheckboxes = document.querySelectorAll('.link-checkbox:checked');
+ [...linkCheckedCheckboxes].forEach((checkbox) => {
+ links.push({
+ id: checkbox.value,
+ title: document.querySelector(`.linklist-item[data-id="${checkbox.value}"] .linklist-link`).innerHTML,
+ });
+ });
+
+ const ids = links.map(item => item.id);
+ window.location = `?change_visibility&token=${token.value}&newVisibility=${visibility}&ids=${ids.join('+')}`;
+ });
+ });
+ }
+
/**
* Select all button
*/
exit;
}
+ // -------- User clicked either "Set public" or "Set private" bulk operation
+ if ($targetPage == Router::$PAGE_CHANGE_VISIBILITY) {
+ if (! $sessionManager->checkToken($_GET['token'])) {
+ die(t('Wrong token.'));
+ }
+
+ $ids = trim($_GET['ids']);
+ if (strpos($ids, ' ') !== false) {
+ // multiple, space-separated ids provided
+ $ids = array_values(array_filter(preg_split('/\s+/', escape($ids))));
+ } else {
+ // only a single id provided
+ $ids = [$ids];
+ }
+
+ // assert at least one id is given
+ if (!count($ids)) {
+ die('no id provided');
+ }
+ // assert that the visibility is valid
+ if (!isset($_GET['newVisibility']) || !in_array($_GET['newVisibility'], ['public', 'private'])) {
+ die('invalid visibility');
+ } else {
+ $private = $_GET['newVisibility'] === 'private';
+ }
+ foreach ($ids as $id) {
+ $id = (int) escape($id);
+ $link = $LINKSDB[$id];
+ $link['private'] = $private;
+ $pluginManager->executeHooks('save_link', $link);
+ $LINKSDB[$id] = $link;
+ }
+ $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
+
+ $location = '?';
+ if (isset($_SERVER['HTTP_REFERER'])) {
+ $location = generateLocation(
+ $_SERVER['HTTP_REFERER'],
+ $_SERVER['HTTP_HOST']
+ );
+ }
+ header('Location: ' . $location); // After deleting the link, redirect to appropriate location
+ exit;
+ }
+
// -------- User clicked the "EDIT" button on a link: Display link edit form.
if (isset($_GET['edit_link'])) {
$id = (int) escape($_GET['edit_link']);
<div id="actions" class="subheader-form">
<div class="pure-g">
<div class="pure-u-1">
- <a href="" id="actions-delete" class="button">{'Delete'|t}</a>
+ <a href="" id="actions-delete" class="button">
+ <i class="fa fa-trash"></i>
+ {'Delete'|t}
+ </a>
+ <a href="" class="actions-change-visibility button" data-visibility="public">
+ <i class="fa fa-globe"></i>
+ {'Set public'|t}
+ </a>
+ <a href="" class="actions-change-visibility button" data-visibility="private">
+ <i class="fa fa-user-secret"></i>
+ {'Set private'|t}
+ </a>
</div>
</div>
</div>