Website Summary Files Commits Branches @commit @diff @stats
path: root / views / archive / meta.php
diff options
context:
space:
mode:
Commite409c1c7123dce3838d6dd1a72b4b0c2f00fba10 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-02-02 12:50:39 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-02-02 12:50:39 +0200
Files08e01d990782d91233296346592c04e52da35d7f /views/archive/meta.php
nowayforward_human-e409c1c7123dce3838d6dd1a72b4b0c2f00fba10.tar
nowayforward_human-e409c1c7123dce3838d6dd1a72b4b0c2f00fba10.tar.gz
nowayforward_human-e409c1c7123dce3838d6dd1a72b4b0c2f00fba10.zip
Parentc83d7e03b607447cb203c0a17edaca9baf1d087f (diff)
feat(views): Separate archive creation to it's own view
1 files changed, 49 insertions, 1 deletions
-rw-r--r--views/archive/meta.php50
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);
+}