From 9121554ce064629dc7aef74434b65ee10756a8a7 Mon Sep 17 00:00:00 2001 From: Georgi Nikolov Date: Sun, 26 Jan 2025 20:28:22 +0200 Subject: Added a navbar on top of the archived pages --- controllers/archive.php | 102 +++++++++++++++++++++++++++++++++++++++++++++++- models/webpage.php | 33 ++++++++++++++++ views/archive/index.php | 4 +- 3 files changed, 136 insertions(+), 3 deletions(-) diff --git a/controllers/archive.php b/controllers/archive.php index 6057a4a..c0dee10 100644 --- a/controllers/archive.php +++ b/controllers/archive.php @@ -339,6 +339,95 @@ class DownloadPage { } } + function getArchiveTop() : array { + $content = 'console.log(\"Debug Objects: " . $output . "\" );"; + } + debugPrintToConsole("This is necessary for some reason, without it the content is not actually shown!"); + + $currentPageId = basename(__DIR__); + $currentPage = Database\Webpage::getPageById($currentPageId); + $requesterUsername = Database\User::fromDBuid($currentPage->RequesterUID); + + $previousPageId = Database\Webpage::getPreviousPageId($currentPage->URL, $currentPage->Date); + $nextPageId = Database\Webpage::getNextPageId($currentPage->URL, $currentPage->Date); + + echo "
"; + echo "
"; + echo "Title: $currentPage->Title"; + echo "Url: $currentPage->URL"; + echo "Date of archival: $currentPage->Date"; + echo "Visits: $currentPage->Visits"; + echo "Requested by: $requesterUsername->Username"; + + echo "
"; + if ($previousPageId != 0) { + echo "Previous version"; + } + if ($nextPageId != 0) { + echo "Next version"; + } + echo "
"; + echo "
"; + ?>'; + + $style = ' + .navbar { + display: flex; + justify-content: space-between; + align-items: center; + background-color: #343a40; + color: #ffffff; + padding: 10px; + border-bottom: 1px solid #ccc; + width: 100%; + position: fixed; + top: 0; + left: 0; + z-index: 1000; + } + + .navbar-info { + display: flex; + justify-content: center; + flex-grow: 1; + } + + .navbar-info span { + margin-right: 15px; + } + + .navbar-links { + display: flex; + gap: 20px; + } + + .navbar a { + text-decoration: none; + color: #007bff; + } + + .navbar a:hover { + text-decoration: underline; + color: #66b3ff; + } + + /* Add some margin to the body to prevent content from being hidden behind the navbar */ + body { + margin-top: 60px; + } + '; + return array($content, $style); + } function createArchive($simular_pages) : void { // Creates the folder with the correct resources and the main html page in a index.html tag @@ -360,8 +449,19 @@ class DownloadPage { $this->changeHyperlinkToLocal($dom, 'a', 'href'); + // Add the header for the archives + list($archive_top, $archive_top_style) = $this->getArchiveTop(); + $phpTag = $dom->createElement('script', $archive_top); + $phpTag->setAttribute('type', 'text/php'); // Set the type to PHP + $body = $dom->getElementsByTagName('body')->item(0); + $body->appendChild($phpTag); + + $styleTag = $dom->createElement('style', $archive_top_style); + $head = $dom->getElementsByTagName('head')->item(0); + $head->appendChild($styleTag); + $this->page_contents = $dom->saveHTML(); - $indexFile = fopen($folder_path . '/index.html', "w"); + $indexFile = fopen($folder_path . '/index.php', "a"); fwrite($indexFile, $this->page_contents); fclose($indexFile); } diff --git a/models/webpage.php b/models/webpage.php index 3445f62..e6d964f 100644 --- a/models/webpage.php +++ b/models/webpage.php @@ -27,6 +27,39 @@ class Webpage extends Table { ); } + static function getPageById(int $id) : Webpage { + return Table::_fromDB( + "SELECT * FROM Webpages WHERE WID = \"$id\"", + "Database\Webpage" + ); + } + + static function getPreviousPageId(string $url, string $date) : int { + $foundId = Table::_get_all( + "Webpages", + "Database\Webpage", + "WHERE URL = \"$url\" && Date < \"$date\" ORDER BY Date DESC LIMIT 1", + "WID" + ); + if (count($foundId) > 0) { + return $foundId[0]->WID; + } + return 0; + } + + static function getNextPageId(string $url, string $date) : int { + $foundId = Table::_get_all( + "Webpages", + "Database\Webpage", + "WHERE URL = \"$url\" && Date > \"$date\" ORDER BY Date ASC LIMIT 1", + "WID" + ); + if (count($foundId) > 0) { + return $foundId[0]->WID; + } + return 0; + } + static function getPagesCount() : int { return Table::_get_entries_count("Webpages"); } diff --git a/views/archive/index.php b/views/archive/index.php index 7d41890..500238a 100644 --- a/views/archive/index.php +++ b/views/archive/index.php @@ -12,7 +12,7 @@ ?> - +
@@ -32,7 +32,7 @@
- URL ?> + URL ?> Date ?>
-- cgit v1.2.3