Skip to content

Commit ef819d7

Browse files
authored
Remove old links (#84)
* added logic for displaying remove url button * added method for checking for old links * implemented new logic for old links and form * changed flashbag message to include URL * Changed verbiage * changed verbiage * changed verbiage * changed verbiage * Changed Verbiage * Changed verbiage * Changed formatting
1 parent b33e95b commit ef819d7

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/goController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ private function handleRouteManage() {
189189
$deleted = $this->lilurl->deleteURL($urlID, $this->auth->getUserId());
190190

191191
if ($deleted) {
192-
$this->flashBag->setParams(self::FLASHBAG_HEADING_DELETE_SUCCESSFUL, '<p>Your URL has been deleted.</p>', $this->flashBag::FLASH_BAG_TYPE_SUCCESS);
192+
$this->flashBag->setParams(self::FLASHBAG_HEADING_DELETE_SUCCESSFUL, '<p>The URL &apos;' . htmlspecialchars($_POST['urlID']) . '&apos; has been deleted.</p>', $this->flashBag::FLASH_BAG_TYPE_SUCCESS);
193193
$this->redirect($this->lilurl->getBaseUrl(self::ROUTE_PATH_LINKS));
194194
} else {
195-
$this->flashBag->setParams(self::FLASHBAG_HEADING_DELETE_FAILED, '<p>Your URL has NOT been deleted.</p>', $this->flashBag::FLASH_BAG_TYPE_ERROR);
195+
$this->flashBag->setParams(self::FLASHBAG_HEADING_DELETE_FAILED, '<p>The URL &apos;' . htmlspecialchars($_POST['urlID']) . '&apos; has NOT been deleted.</p>', $this->flashBag::FLASH_BAG_TYPE_ERROR);
196196
$this->redirect($this->lilurl->getBaseUrl(self::ROUTE_PATH_LINKS));
197197
}
198198

src/lilURL.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class lilURL
2323
const MAX_RANDOM_ID_BUMP_LENGTH = 5;
2424
const MAX_RANDOM_ID_ATTEMPTS = 15000000;
2525

26+
const MIN_YEARS_OLD_LINK = 2;
27+
2628
// Tables
2729
const TABLE_GROUPS = 'tblGroups';
2830
const TABLE_GROUP_USERS = 'tblGroupUsers';
@@ -632,9 +634,19 @@ public function userHasURLAccess($urlID, $uid) {
632634
return $this->userOwnsURL($urlID, $uid) || $this->userHasGroupURLAccess($urlID, $uid);
633635
}
634636

637+
public function checkOldURL($urlID)
638+
{
639+
$result = $this->db->run(
640+
'SELECT count(*) AS oldURL FROM ' . self::TABLE_URLS . ' WHERE ' . self::WHERE_URL_ID . ' AND ((lastRedirect <= DATE_SUB(CURDATE(), INTERVAL ' . self::MIN_YEARS_OLD_LINK . ' YEAR)) OR (lastRedirect IS NULL AND submitDate <= DATE_SUB(CURDATE(), INTERVAL ' . self::MIN_YEARS_OLD_LINK . ' YEAR)));',
641+
array(self::PDO_PLACEHOLDER_URL_ID => $urlID),
642+
TRUE
643+
);
644+
return $result->oldURL > 0;
645+
}
646+
635647
public function deleteURL($urlID, $uid)
636648
{
637-
if ($this->userHasURLAccess($urlID, $uid)) {
649+
if ($this->userHasURLAccess($urlID, $uid) || $this->checkOldURL($urlID)) {
638650
return $this->db->delete(
639651
self::TABLE_URLS,
640652
self::WHERE_URL_ID . ' LIMIT 1',

www/templates/linkinfo.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@
9191
<?php endif; ?>
9292
</dd>
9393
<?php endif; ?>
94+
95+
96+
<?php if ($lilurl->checkOldURL($link->urlID)): ?>
97+
<form class="dcf-form dcf-mb-0" action="<?php echo htmlspecialchars($lilurl->getBaseUrl('a/links')) ?>" method="post">
98+
<input type="hidden" name="urlID" value="<?php echo $link->urlID; ?>" />
99+
<p class="dcf-bg-white dcf-p-4 dcf-rounded">
100+
This URL has NOT been used or created in the past two years. You may delete this URL if you would like to use it for a different purpose.
101+
<button class="dcf-btn dcf-btn-primary dcf-d-block dcf-mt-4" type="submit" onclick="return confirm('Are you for sure you want to delete \'<?php echo $link->urlID; ?>\'?');">Delete</button>
102+
</p>
103+
</form>
104+
<?php else:?>
105+
<p class="dcf-bg-white dcf-p-4 dcf-rounded">
106+
This URL has been used or created in the past two years. You will be unable to delete it for now, but you can always ask the person who created the URL to delete it.
107+
</p>
108+
<?php endif; ?>
109+
94110
</dl>
95111
</div>
96112
<?php endif; ?>

0 commit comments

Comments
 (0)