From 9863aa1bfcf0ce9874034bfc8fff05fd428c8019 Mon Sep 17 00:00:00 2001 From: Georgi Nikolov Date: Sat, 25 Jan 2025 18:31:11 +0200 Subject: Added a title field in the database --- controllers/archive_page.php | 13 ++++++++++++- migrations/00-initial.sql | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/controllers/archive_page.php b/controllers/archive_page.php index 37ce4ee..9467eab 100644 --- a/controllers/archive_page.php +++ b/controllers/archive_page.php @@ -13,6 +13,7 @@ class DownloadPage { private $page_url; private $page_contents; private $favicon_path; + private $page_title; private function debugPrintToConsole($data) : void{ $output = $data; @@ -38,7 +39,7 @@ class DownloadPage { // Fallback and try to download them from the server directly $this->tryDownloadFavicon(); } - Database\Webpage::create($folder_location, $page_url, 1, $this->favicon_path); + Database\Webpage::create($folder_location, $page_url, 1, $this->favicon_path, $this->page_title); } else { echo "Website does not exist"; } @@ -247,6 +248,14 @@ class DownloadPage { return ($code >= 200 && $code < 400); } + function updatePageTitle(&$dom) { + $titles = $dom->getElementsByTagName("title"); + if ($titles->length > 0) { + $this->page_title = $titles->item(0)->textContent; + } + } + + function createArchive($simular_pages) : void { // Creates the folder with the correct resources and the main html page in a index.html tag $dom = new DOMDocument(); @@ -262,6 +271,8 @@ class DownloadPage { $this->downloadSource($dom, $folder_path, 'script', 'src', $simular_pages); $this->downloadSource($dom, $folder_path, 'img', 'src', $simular_pages); + $this->updatePageTitle($dom); + $this->changeHyperlinkToLocal($dom, 'a', 'href'); $this->page_contents = $dom->saveHTML(); diff --git a/migrations/00-initial.sql b/migrations/00-initial.sql index a072863..ba00b32 100644 --- a/migrations/00-initial.sql +++ b/migrations/00-initial.sql @@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS Webpages ( Visits INT NOT NULL, RequesterUID INT NOT NULL, FaviconPath VARCHAR(512), + Title VARCHAR(64), PRIMARY KEY (WID), FOREIGN KEY (RequesterUID) REFERENCES Users(UID) ); -- cgit v1.2.3