diff options
| author | Georgi Nikolov <ggeorgi60@gmail.com> | 2025-01-25 17:01:26 +0200 |
|---|---|---|
| committer | Georgi Nikolov <ggeorgi60@gmail.com> | 2025-01-25 17:01:26 +0200 |
| commit | e143770fc296e34862d95272fc79a56fa9d20a34 (patch) | |
| tree | 2bcbf53e686619bddec5da28d5775656b26b5ea0 /controllers | |
| parent | db285a4be28e6da35be65424b2f324dd04e9becf (diff) | |
| download | nowayforward_human-e143770fc296e34862d95272fc79a56fa9d20a34.tar nowayforward_human-e143770fc296e34862d95272fc79a56fa9d20a34.tar.gz nowayforward_human-e143770fc296e34862d95272fc79a56fa9d20a34.zip | |
Added additional table column for the favicon in the database
With that commit handled the saving of that favicon as well
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/archive_page.php | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/controllers/archive_page.php b/controllers/archive_page.php index fddea57..be73757 100644 --- a/controllers/archive_page.php +++ b/controllers/archive_page.php @@ -12,6 +12,7 @@ class DownloadPage { private $folder_name; private $page_url; private $page_contents; + private $favicon_path; private function debugPrintToConsole($data) : void{ $output = $data; @@ -29,9 +30,10 @@ class DownloadPage { $page_url_pattern = $this->getCorrectLinkPattern($page_url); $simular_pages = Database\Webpage::getArchivePathsByPattern('%' . $page_url_pattern . '%'); if ($website_exists) { - $this->folder_name = Database\Webpage::create($folder_location, $page_url, 1); + $this->folder_name = Database\Webpage::getPagesCount() + 1; $this->page_contents = $this->downloadFile($this->page_url); $this->createArchive($simular_pages); + Database\Webpage::create($folder_location, $page_url, 1, $this->favicon_path); } else { echo "Website does not exist"; } @@ -132,6 +134,9 @@ class DownloadPage { // change the link to point to the source of the previous archive instead of downloading a news source $link->setAttribute($attribute, "../" . $page->WID . "/" . $resourceName); $found_resource = true; + if (str_contains($resourceName, "favicon")) { + $this->favicon_path = $page->WID . "/" . $resourceName; + } break; } } @@ -139,12 +144,16 @@ class DownloadPage { if (!$found_resource) { // Page is unique so there will be no resource that can be cached - $link->setAttribute($attribute, './' . basename($source)); - $file = fopen($folder_path . '/' . basename($source), "w"); + $resourceName = basename($source); + $link->setAttribute($attribute, './' . $resourceName); + $file = fopen($folder_path . '/' . $resourceName, "w"); if ($file){ fwrite($file, $sourceContent); fclose($file); } + if (str_contains($resourceName, "favicon")) { + $this->favicon_path = $this->folder_name . "/" . $resourceName; + } } } } @@ -174,7 +183,6 @@ class DownloadPage { // If there are no pages that are like that url point to the landing page of the site // that says that this page was not yet archived $tag->setAttribute($attribute, "../../archive/index.php?page_url=" . $this->baseToFullUrlForGet($this->page_url, $link)); - $this->debugPrintToConsole($this->baseToFullUrlForGet($this->page_url, $link)); } } } |
