aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2025-02-01 09:54:32 +0200
committerSyndamia <kamen@syndamia.com>2025-02-01 10:28:22 +0200
commit5a0d4f4a00c9162fbf773ca6b73d34354c6650fe (patch)
treed1bb3d750c295916fc393d671afeba6276185d85
parentd6212a96b01d855c49da58a085c07cf540654db7 (diff)
downloadnowayforward_human-5a0d4f4a00c9162fbf773ca6b73d34354c6650fe.tar
nowayforward_human-5a0d4f4a00c9162fbf773ca6b73d34354c6650fe.tar.gz
nowayforward_human-5a0d4f4a00c9162fbf773ca6b73d34354c6650fe.zip
feat(archive): Include topbar dynamically
So now changes to views/archive/topbar.php and views/archive/topbar.css will "propagate" to all archives, no matter when they were made
-rw-r--r--controllers/archive.php18
-rw-r--r--views/archive/topbar.php13
2 files changed, 13 insertions, 18 deletions
diff --git a/controllers/archive.php b/controllers/archive.php
index c1ff4a2..9b8ac16 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -354,13 +354,6 @@ class DownloadPage {
}
}
- function getArchiveTop() : array {
- return array(
- file_get_contents(__DIR__ . '/../views/archive/topbar.php'),
- file_get_contents(__DIR__ . '/../views/archive/topbar.css')
- );
- }
-
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();
@@ -382,12 +375,17 @@ 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 = $dom->createElement('script', '
+ </script>
+ <?php require_once "' . __DIR__ . '/../views/archive/topbar.php" ?>
+ <script>
+ ');
$body = $dom->getElementsByTagName('body')->item(0);
$body->appendChild($phpTag);
- $styleTag = $dom->createElement('style', $archive_top_style);
+ $styleTag = $dom->createElement('link', '');
+ $styleTag->setAttribute('rel', 'stylesheet');
+ $styleTag->setAttribute('href', '/archive/topbar.css');
$head = $dom->getElementsByTagName('head')->item(0);
$head->appendChild($styleTag);
diff --git a/views/archive/topbar.php b/views/archive/topbar.php
index f521fcb..b00a33d 100644
--- a/views/archive/topbar.php
+++ b/views/archive/topbar.php
@@ -1,17 +1,14 @@
-<!-- Dirty hack to escape all PHP dom sanitization and checks -->
-</script>
-
<?php
require_once "../../models/database.php";
require_once "../../models/webpage.php";
require_once "../../models/user.php";
- $currentPageId = basename(__DIR__);
+ $currentPageId = explode('/', $_SERVER['REQUEST_URI'], 4)[2];
$currentPage = Database\Webpage::fromDBwid($currentPageId);
- $requesterUsername = Database\User::fromDBuid($currentPage->RequesterUID);
+ $requester = Database\User::fromDBuid($currentPage->RequesterUID);
- $previousPageId = Database\Webpage::getPreviousPageId($currentPage->URL, $currentPage->Date);
- $nextPageId = Database\Webpage::getNextPageId($currentPage->URL, $currentPage->Date);
+ $previousPageId = $currentPage->previousPageId();
+ $nextPageId = $currentPage->nextPageId();
?>
<div class="navbar">
@@ -20,7 +17,7 @@
<span>Url: <?= $currentPage->URL ?></span>
<span>Date of archival: <?= $currentPage->Date ?></span>
<span>Visits: <?= $currentPage->Visits ?></span>
- <span>Requested by: <?= $requesterUsername->Username ?></span>
+ <span>Requested by: <?= $requester->Username ?></span>
</div>
<div class="navbar-links">