Add temporary links
Fixes #4. Also removes statistics since those have been replaced by GoatCounter anyway.
This commit is contained in:
parent
7e96b63a86
commit
9370724b35
|
@ -23,7 +23,6 @@ $needs_confirmation = false;
|
|||
try {
|
||||
$links = new Links(".links.db", "links.sql");
|
||||
list($target, $needs_confirmation) = $links->getTarget($path);
|
||||
$links->handleVisit($path);
|
||||
} catch (Exception $exception) {
|
||||
$error = true;
|
||||
}
|
||||
|
@ -63,7 +62,7 @@ if ($target != null && !$needs_confirmation) {
|
|||
<h3>Internal server error</h3>
|
||||
<p>Something went wrong internally, and you could not be redirected. Please try again later.</p>
|
||||
<?php
|
||||
} else if ($target != null && $needs_confirmation) {
|
||||
} else if ($needs_confirmation) {
|
||||
?>
|
||||
<h3>Confirm redirect</h3>
|
||||
<p>This URL redirects to <b><?= $target ?></b>.</p>
|
||||
|
@ -107,7 +106,7 @@ if ($target != null && !$needs_confirmation) {
|
|||
$("#header").appendChild(header({title: "fwdkr.co"}));
|
||||
$("#footer").appendChild(footer({
|
||||
vcsURL: "https://git.fwdekker.com/FWDekker/fwdkr.co/",
|
||||
version: "v1.3.4"
|
||||
version: "v1.4.0"
|
||||
}));
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -28,6 +28,8 @@ class Links
|
|||
$this->db = new SQLite3($database, SQLITE3_OPEN_READWRITE);
|
||||
}
|
||||
$this->db->enableExceptions(true);
|
||||
|
||||
$this->deleteExpiredLinks();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,15 +59,12 @@ class Links
|
|||
}
|
||||
|
||||
/**
|
||||
* Increments the visit counter and visit date of the given path.
|
||||
*
|
||||
* @param string $path the path to handle a visit to
|
||||
* Deletes all expired links.
|
||||
*/
|
||||
function handleVisit(string $path)
|
||||
{
|
||||
$stmt = $this->db->prepare("UPDATE links SET visits = visits + 1, last_visit = CURRENT_TIMESTAMP
|
||||
WHERE path = :path;");
|
||||
$stmt->bindValue(":path", $path);
|
||||
function deleteExpiredLinks(): void {
|
||||
$now = date("Y-m-d H:i:s");
|
||||
$stmt = $this->db->prepare("DELETE FROM links WHERE expires_at < :now;");
|
||||
$stmt->bindValue(":now", $now);
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,8 @@ create table links
|
|||
constraint links_pk
|
||||
primary key,
|
||||
target text not null,
|
||||
needs_confirmation boolean default false not null,
|
||||
visits int default 0 not null,
|
||||
last_visit text
|
||||
needs_confirmation boolean default false not null,
|
||||
expires_at datetime default null
|
||||
);
|
||||
|
||||
create unique index links_path_uindex
|
||||
|
|
Loading…
Reference in New Issue