diff options
| -rw-r--r-- | controllers/archive.php | 54 | ||||
| -rw-r--r-- | views/archive/create/index.php | 1 | ||||
| -rw-r--r-- | views/archive/create/meta.php | 5 | ||||
| -rw-r--r-- | views/archive/index.php | 12 | ||||
| -rw-r--r-- | views/archive/meta.php | 50 | ||||
| -rw-r--r-- | views/global/router.php | 2 |
6 files changed, 67 insertions, 57 deletions
diff --git a/controllers/archive.php b/controllers/archive.php index ffe9c70..fd278ff 100644 --- a/controllers/archive.php +++ b/controllers/archive.php @@ -7,7 +7,7 @@ use Exception; function on_post() { global $TOKEN; - $WEBSITE_CATEGORY = 'page_url'; + $WEBSITE_CATEGORY = 'url'; $DOWNLOADS_FOLDER = getenv('ARCHIVES_DIR'); $website_url = $_POST[$WEBSITE_CATEGORY]; $uid = 1; @@ -18,6 +18,9 @@ function on_post() { catch (Exception $e) {} } $currentPage = new DownloadPage($website_url, $DOWNLOADS_FOLDER, $uid); + + header('Location: /archive/?url=' . $website_url); + exit(); } class DownloadPage { @@ -404,52 +407,3 @@ class DownloadPage { fclose($indexFile); } } - -function applyCorrectProtocol($url, $protocol) : string { - if (str_contains($url, $protocol)) { - return $url; - } - return $protocol . $url; -} - -function normalizeUrl(string &$url) : void { - $count_slashes = substr_count($url, "/"); - if (str_ends_with($url, "/index.html")) { - $url = substr($url, 0, strlen($url) - strlen("/index.html")); - } - elseif (str_ends_with($url, "/index")) { - $url = substr($url, 0, strlen($url) - strlen("/index")); - } - elseif (str_ends_with($url, "/")) { - $url = substr($url, 0, -1); - } -} - -function doesWebsiteExist($url) : array { - // Check if the site exists with https - $https_url = applyCorrectProtocol($url, "https://"); - if ($https_url != $url) { - $url_headers = @get_headers($https_url); - if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') { - return array(true, $https_url); - } - } - - // Check if the site exists with http - $http_url = applyCorrectProtocol($url, "http://"); - if ($http_url != $url) { - $url_headers = @get_headers($http_url); - if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') { - return array(true, $http_url); - } - } - - // Check if the site exists as is - // Will take effect when the user has entered the https/http protocol with the site - $url_headers = @get_headers($url); - if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') { - return array(true, $url); - } - - return array(false, $url); -} diff --git a/views/archive/create/index.php b/views/archive/create/index.php new file mode 100644 index 0000000..378d2de --- /dev/null +++ b/views/archive/create/index.php @@ -0,0 +1 @@ +<h2>Archiving <?= $url ?>...</h2> diff --git a/views/archive/create/meta.php b/views/archive/create/meta.php new file mode 100644 index 0000000..b5ad130 --- /dev/null +++ b/views/archive/create/meta.php @@ -0,0 +1,5 @@ +<?php + +$url = $_POST['url']; +$title = "Archiving $url..."; +$controller = 'archive'; diff --git a/views/archive/index.php b/views/archive/index.php index f7c427f..73e1017 100644 --- a/views/archive/index.php +++ b/views/archive/index.php @@ -3,8 +3,8 @@ $page = null; try { - list($exists, $url) = Controller\doesWebsiteExist($url); - Controller\normalizeUrl($url); + list($exists, $url) = doesWebsiteExist($url); + normalizeUrl($url); $page = Database\Webpage::fromDB($url); $page->incrementVisits(); @@ -16,8 +16,8 @@ <?php if ($page !== null): ?> <iframe src="<?= "/archives/{$page->WID}/index.php" ?>" scrolling="no"></iframe> - <form action="#" method="POST"> - <input type="hidden" name="page_url" value="<?= $url ?>"> + <form action="/archive/create" method="POST"> + <input type="hidden" name="url" value="<?= $url ?>"> <input type="submit" value="Archive Now!"> </form> <!-- Button to add to list --> @@ -39,8 +39,8 @@ <?php else: ?> <h2>"<?= $url ?>" hasn't been archived yet!</h2> - <form action="#" method="POST"> - <input type="hidden" name="page_url" value="<?= $url ?>"> + <form action="/archive/create" method="POST"> + <input type="hidden" name="url" value="<?= $url ?>"> <input type="submit" value="Archive Now!"> </form> diff --git a/views/archive/meta.php b/views/archive/meta.php index 001d07c..3c37565 100644 --- a/views/archive/meta.php +++ b/views/archive/meta.php @@ -2,4 +2,52 @@ $url = $_GET['url']; $title = $url . ' archive'; -$controller = 'archive'; + +function normalizeUrl(string &$url) : void { + $count_slashes = substr_count($url, "/"); + if (str_ends_with($url, "/index.html")) { + $url = substr($url, 0, strlen($url) - strlen("/index.html")); + } + elseif (str_ends_with($url, "/index")) { + $url = substr($url, 0, strlen($url) - strlen("/index")); + } + elseif (str_ends_with($url, "/")) { + $url = substr($url, 0, -1); + } +} + +function applyCorrectProtocol($url, $protocol) : string { + if (str_contains($url, $protocol)) { + return $url; + } + return $protocol . $url; +} + +function doesWebsiteExist($url) : array { + // Check if the site exists with https + $https_url = applyCorrectProtocol($url, "https://"); + if ($https_url != $url) { + $url_headers = @get_headers($https_url); + if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') { + return array(true, $https_url); + } + } + + // Check if the site exists with http + $http_url = applyCorrectProtocol($url, "http://"); + if ($http_url != $url) { + $url_headers = @get_headers($http_url); + if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') { + return array(true, $http_url); + } + } + + // Check if the site exists as is + // Will take effect when the user has entered the https/http protocol with the site + $url_headers = @get_headers($url); + if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') { + return array(true, $url); + } + + return array(false, $url); +} diff --git a/views/global/router.php b/views/global/router.php index b668f33..16e143e 100644 --- a/views/global/router.php +++ b/views/global/router.php @@ -31,6 +31,8 @@ function route_view() { case '/list/new': return '/list/new'; case '/list/add': return '/list/add'; case '/list/delete': return '/list/delete'; + + case '/archive/create': return '/archive/create'; } switch ($root) { |
