aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgi Nikolov <ggeorgi60@gmail.com>2025-01-25 17:01:26 +0200
committerGeorgi Nikolov <ggeorgi60@gmail.com>2025-01-25 17:01:26 +0200
commite143770fc296e34862d95272fc79a56fa9d20a34 (patch)
tree2bcbf53e686619bddec5da28d5775656b26b5ea0
parentdb285a4be28e6da35be65424b2f324dd04e9becf (diff)
downloadnowayforward_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
-rw-r--r--controllers/archive_page.php16
-rw-r--r--migrations/00-initial.sql1
-rw-r--r--models/database.php7
-rw-r--r--models/webpage.php11
4 files changed, 28 insertions, 7 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));
}
}
}
diff --git a/migrations/00-initial.sql b/migrations/00-initial.sql
index f50d9d2..0edf29b 100644
--- a/migrations/00-initial.sql
+++ b/migrations/00-initial.sql
@@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS Webpages (
Date DATETIME NOT NULL,
Visits INT NOT NULL,
RequesterUID INT NOT NULL,
+ FaviconPath VARCHAR(512) NOT NULL,
PRIMARY KEY (WID),
FOREIGN KEY (RequesterUID) REFERENCES Users(UID)
);
diff --git a/models/database.php b/models/database.php
index 62f5b10..f472dbb 100644
--- a/models/database.php
+++ b/models/database.php
@@ -33,6 +33,13 @@ abstract class Table {
return $id;
}
+ static protected function _get_entries_count(string $table) : int {
+ $conn = Table::connect();
+ $query = $conn->query("SELECT count(*) FROM $table");
+ $conn = null;
+ return $query->fetchColumn();
+ }
+
static protected function _update(string $table, string $sets, string $identify) {
$conn = Table::connect();
$query = $conn->query("UPDATE $table SET $sets WHERE $identify");
diff --git a/models/webpage.php b/models/webpage.php
index 1a2f4a6..5dd44e0 100644
--- a/models/webpage.php
+++ b/models/webpage.php
@@ -9,12 +9,13 @@ class Webpage extends Table {
public $Date;
public $Visits;
public $RequesterUID;
+ public $FaviconPath;
- static function create(string $Path, string $URL, int $RequesterUID) : int {
+ static function create(string $Path, string $URL, int $RequesterUID, string $FaviconPath) : int {
return Table::_create(
'Webpages',
- '(Path, URL, Date, Visits, RequesterUID)',
- "(\"$Path\", \"$URL\", (NOW() + INTERVAL 2 HOUR), 0, \"$RequesterUID\")"
+ '(Path, URL, Date, Visits, RequesterUID, FaviconPath)',
+ "(\"$Path\", \"$URL\", (NOW() + INTERVAL 2 HOUR), 0, \"$RequesterUID\", \"$FaviconPath\")"
);
}
@@ -25,6 +26,10 @@ class Webpage extends Table {
);
}
+ static function getPagesCount() : int {
+ return Table::_get_entries_count("Webpages");
+ }
+
static function mostVisited(int $count) : array {
return Table::_get_all(
'Webpages',