From c36724bb6cb37e03d72b0d6f0995e0a91b871edf Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 19 Jan 2025 07:44:57 +0200 Subject: feat: Move archive_page logic from src to controllers --- src/archive_page.php | 98 ---------------------------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/archive_page.php (limited to 'src') diff --git a/src/archive_page.php b/src/archive_page.php deleted file mode 100644 index 16aac8a..0000000 --- a/src/archive_page.php +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - PHP answer to the request - - -

-zip_location = $zip_location; - $this->zip_name = $zip_name; - $this->page_url = $page_url; - list($website_exists, $this->page_url) = $this->does_website_exist($this->page_url); - if ($website_exists) { - $this->page_contents = file_get_contents($this->page_url); - $zip = $this->create_zip_archive(); - } else { - echo "Website does not exist"; - } - } - - function set_zip_location($zip_location) { - $this->zip_location = $zip_location; - } - function set_zip_name($zip_name) { - $this->zip_name = $zip_name; - } - function set_page_url($page_url) { - $this->page_url = $page_url; - } - function apply_correct_protocol($url, $protocol) { - if (str_contains($url, $protocol)) { - return $url; - } - - return $protocol . $url; - } - - function does_website_exist($url) { - - // Check if the site exists with https - $https_url = $this->apply_correct_protocol($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 = $this->apply_correct_protocol($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); - } - - function create_zip_archive() { - // Creates and returns a zip object resulted from zipping the page that was downloaded - $zip = new ZipArchive(); - if ($zip->open($this->zip_location . $this->zip_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) == TRUE) { - $zip->addFromString('index.html', $this->page_contents); - $zip->close(); - } else { - echo "Zip archive could not be open"; - } - - return $zip; - } - } -?> -

- - -- cgit v1.2.3