aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2025-01-18 20:59:11 +0200
committerKamen Mladenov <kamen@syndamia.com>2025-01-19 07:46:17 +0200
commite9af7ba259281472e299ae06daee361b44cfdb42 (patch)
tree84a5789f07e31b6c03f40202e650ed05ee9c5c4a
parent68f9981680844e876636369cb07137b351b23989 (diff)
downloadnowayforward_human-e9af7ba259281472e299ae06daee361b44cfdb42.tar
nowayforward_human-e9af7ba259281472e299ae06daee361b44cfdb42.tar.gz
nowayforward_human-e9af7ba259281472e299ae06daee361b44cfdb42.zip
feat(views): Rework sample_archive into the new format
-rw-r--r--controllers/archive_page.php41
-rw-r--r--views/sample_archive/index.html13
-rw-r--r--views/sample_archive/index.php11
3 files changed, 52 insertions, 13 deletions
diff --git a/controllers/archive_page.php b/controllers/archive_page.php
new file mode 100644
index 0000000..593076f
--- /dev/null
+++ b/controllers/archive_page.php
@@ -0,0 +1,41 @@
+<?php
+
+function on_post() {
+ $WEBSITE_CATEGORY = 'page_url';
+ $website_url = $_POST[$WEBSITE_CATEGORY];
+ $website_exists = does_website_exist($website_url) ? "true" : "false";
+ echo "Website exists: $website_exists" . "<br/>";
+}
+
+function apply_correct_protocol($url, $protocol) {
+ if (str_contains($url, $protocol)) {
+ return $url;
+ }
+
+ return $protocol . $url;
+}
+
+function does_website_exist($url) {
+ $result = false;
+
+ // Check if the site exists with https
+ $https_url = apply_correct_protocol($url, "https://");
+ if ($https_url != $url) {
+ $url_headers = @get_headers($https_url);
+ $result |= $url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found';
+ }
+
+ // Check if the site exists with http
+ $http_url = apply_correct_protocol($url, "http://");
+ if ($http_url != $url) {
+ $url_headers = @get_headers($http_url);
+ $result |= $url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found';
+ }
+
+ // 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);
+ $result |= $url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found';
+
+ return $result;
+}
diff --git a/views/sample_archive/index.html b/views/sample_archive/index.html
deleted file mode 100644
index ea21c31..0000000
--- a/views/sample_archive/index.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE html>
-<html lang="bg">
-<head>
- <meta charset="UTF-8">
- <title>Archive a page</title>
-</head>
-<body>
- <form action="../../src/archive_page.php" method="POST">
- <input type="text" name="page_url">
- <input type="submit" name"archive_page_button">
- </form>
-</body>
-</html>
diff --git a/views/sample_archive/index.php b/views/sample_archive/index.php
new file mode 100644
index 0000000..9d7addd
--- /dev/null
+++ b/views/sample_archive/index.php
@@ -0,0 +1,11 @@
+<?php
+ include '../meta.php';
+ runController('archive_page');
+?>
+
+<form action="/sample_archive/index.php" method="POST">
+ <input type="text" name="page_url">
+ <input type="submit" name="archive_page_button">
+</form>
+
+<?php end_page(); ?>