aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controllers/archive.php14
-rw-r--r--views/archive/index.php10
2 files changed, 21 insertions, 3 deletions
diff --git a/controllers/archive.php b/controllers/archive.php
index 0d21a1e..6057a4a 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -2,12 +2,20 @@
namespace Controller;
use Database;
use DOMDocument;
+use Exception;
function on_post() {
$WEBSITE_CATEGORY = 'page_url';
$DOWNLOADS_FOLDER = getenv('ARCHIVES_DIR');
$website_url = $_POST[$WEBSITE_CATEGORY];
- $currentPage = new DownloadPage($website_url, $DOWNLOADS_FOLDER);
+ $uid = 1;
+ if (array_key_exists('token', $_POST) && strlen($_POST['token']) === 36) {
+ try {
+ $uid = Database\Cookie::fromDB($_POST['token'])->UID;
+ }
+ catch (Exception $e) {}
+ }
+ $currentPage = new DownloadPage($website_url, $DOWNLOADS_FOLDER, $uid);
}
class DownloadPage {
@@ -18,7 +26,7 @@ class DownloadPage {
private $favicon_path;
private $page_title;
- function __construct($page_url, $folder_location) {
+ function __construct($page_url, $folder_location, $requester_uid) {
$this->folder_location = $folder_location;
$this->page_url = $page_url;
list($website_exists, $this->page_url) = $this->doesWebsiteExist($this->page_url);
@@ -34,7 +42,7 @@ class DownloadPage {
// Fallback and try to download them from the server directly
$this->tryDownloadFavicon();
}
- Database\Webpage::create($folder_location, $page_url, 1, $this->favicon_path, $this->page_title);
+ Database\Webpage::create($folder_location, $page_url, $requester_uid, $this->favicon_path, $this->page_title);
} else {
echo "Website does not exist";
}
diff --git a/views/archive/index.php b/views/archive/index.php
index 2c784de..7d41890 100644
--- a/views/archive/index.php
+++ b/views/archive/index.php
@@ -16,8 +16,13 @@
<form action="#" method="POST">
<input type="hidden" name="page_url" value="<?= $url ?>">
+ <input id="token" type="hidden" name="token" value="">
<input type="submit" value="Archive Now!">
</form>
+ <script type="text/javascript">
+ const tokenInput = document.getElementById('token');
+ tokenInput.value = sessionStorage.getItem('token');
+ </script>
<!-- Button to add to list -->
<!-- Button to delete -->
@@ -54,7 +59,12 @@
<h2>"<?= $url ?>" hasn't been archived yet!</h2>
<form action="#" method="POST">
<input type="hidden" name="page_url" value="<?= $url ?>">
+ <input id="token" type="hidden" name="token" value="">
<input type="submit" value="Archive Now!">
</form>
+ <script type="text/javascript">
+ const tokenInput = document.getElementById('token');
+ tokenInput.value = sessionStorage.getItem('token');
+ </script>
<?php endif; ?>