aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controllers/archive.php3
-rw-r--r--models/archivelist.php8
-rw-r--r--models/user.php16
-rw-r--r--models/webpage.php71
-rw-r--r--views/archive/index.php2
-rw-r--r--views/home/index.php2
-rw-r--r--views/list/update/index.php4
-rw-r--r--views/profile/index.php4
8 files changed, 56 insertions, 54 deletions
diff --git a/controllers/archive.php b/controllers/archive.php
index 9b8ac16..70f2b6d 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -37,6 +37,9 @@ class DownloadPage {
$page_url_pattern = $this->getCorrectLinkPattern($this->page_url);
$simular_pages = Database\Webpage::getArchivePathsByPattern('%' . $page_url_pattern . '%');
if ($website_exists) {
+ // NOTE: This is incredibly dumb, Databas\Webpage::create returns the
+ // auto-incremented ID, so it should be used here.
+ // The logic needs to be reorganized!
$this->folder_name = Database\Webpage::getPagesCount() + 1;
$this->page_contents = $this->downloadFile($this->page_url);
$this->createArchive($simular_pages);
diff --git a/models/archivelist.php b/models/archivelist.php
index 75bee1f..779365e 100644
--- a/models/archivelist.php
+++ b/models/archivelist.php
@@ -23,14 +23,6 @@ class ArchiveList extends Table {
);
}
- static function allListsByUser(int $UID) : array {
- return Table::_get_all(
- 'ArchiveLists',
- 'Database\ArchiveList',
- "WHERE AuthorUID = \"$UID\""
- );
- }
-
function addItem(int $WID) {
Table::_create(
'ArchiveListsWebpages',
diff --git a/models/user.php b/models/user.php
index eff2c3e..04f5a83 100644
--- a/models/user.php
+++ b/models/user.php
@@ -31,7 +31,19 @@ class User extends Table {
);
}
- static function get_all() : array {
- return Table::_get_all("Users", "Database\User");
+ function archives() : array {
+ return Table::_get_all(
+ 'Webpages',
+ 'Database\Webpage',
+ "WHERE RequesterUID = \"$this->UID\" ORDER BY Date DESC"
+ );
+ }
+
+ function archiveLists() : array {
+ return Table::_get_all(
+ 'ArchiveLists',
+ 'Database\ArchiveList',
+ "WHERE AuthorUID = \"$this->UID\""
+ );
}
}
diff --git a/models/webpage.php b/models/webpage.php
index ceb9cea..6347397 100644
--- a/models/webpage.php
+++ b/models/webpage.php
@@ -34,37 +34,12 @@ class Webpage extends Table {
);
}
- 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;
- }
-
+ // TODO: remove this, refer to archive.php
static function getPagesCount() : int {
return Table::_get_entries_count("Webpages");
}
- static function mostVisited(int $count) : array {
+ static function fromDBmostVisited(int $count) : array {
return Table::_get_all(
'Webpages',
'Database\Webpage',
@@ -73,29 +48,51 @@ class Webpage extends Table {
);
}
- static function allArchives(string $URL) : array {
+ static function getArchivePathsByPattern(string $URLPattern) : array {
return Table::_get_all(
'Webpages',
'Database\Webpage',
- "WHERE URL = \"$URL\" ORDER BY Date DESC"
+ "WHERE URL LIKE \"$URLPattern\" ORDER BY Date DESC",
+ "Path, WID"
);
}
- static function allArchivesByUser(int $UID) : array {
+ function allArchives() : array {
return Table::_get_all(
'Webpages',
'Database\Webpage',
- "WHERE RequesterUID = \"$UID\" ORDER BY Date DESC"
+ "WHERE URL = \"$this->URL\" ORDER BY Date DESC"
);
}
- static function getArchivePathsByPattern(string $URLPattern) : array {
- return Table::_get_all(
- 'Webpages',
- 'Database\Webpage',
- "WHERE URL LIKE \"$URLPattern\" ORDER BY Date DESC",
- "Path, WID"
+ function previousPageId() : int {
+ $foundId = Table::_get_all(
+ "Webpages",
+ "Database\Webpage",
+ "WHERE URL = \"$this->URL\" AND Date < \"$this->Date\"
+ ORDER BY Date DESC
+ LIMIT 1",
+ "WID"
);
+ if (count($foundId) > 0) {
+ return $foundId[0]->WID;
+ }
+ return 0;
+ }
+
+ function nextPageId() : int {
+ $foundId = Table::_get_all(
+ "Webpages",
+ "Database\Webpage",
+ "WHERE URL = \"$this->URL\" AND Date > \"$this->Date\"
+ ORDER BY Date ASC
+ LIMIT 1",
+ "WID"
+ );
+ if (count($foundId) > 0) {
+ return $foundId[0]->WID;
+ }
+ return 0;
}
function incrementVisits() {
diff --git a/views/archive/index.php b/views/archive/index.php
index 085a033..846f910 100644
--- a/views/archive/index.php
+++ b/views/archive/index.php
@@ -24,7 +24,7 @@
<!-- Button to delete -->
<h2>Archives by date:</h2>
- <?php foreach (Database\Webpage::allArchives($page->URL) as $page): ?>
+ <?php foreach ($page->allArchives() as $page): ?>
<section class="item">
<section>
<div>
diff --git a/views/home/index.php b/views/home/index.php
index abc872b..e14e23a 100644
--- a/views/home/index.php
+++ b/views/home/index.php
@@ -11,7 +11,7 @@
<h1>Most popular archives</h1>
-<?php foreach(Database\Webpage::mostVisited(10) as $page): ?>
+<?php foreach(Database\Webpage::fromDBmostVisited(10) as $page): ?>
<section class="card" onclick="goto_archive('<?= $page->URL ?>')">
<section class="quickinfo">
<a href="<?= $page->URL ?>"><?= $page->URL ?></a>
diff --git a/views/list/update/index.php b/views/list/update/index.php
index 6fa91e1..b3737f0 100644
--- a/views/list/update/index.php
+++ b/views/list/update/index.php
@@ -4,12 +4,10 @@
<?php
$user = null;
$webpage = null;
- $lists = null;
try {
$user = Database\Cookie::fromDB($TOKEN);
$webpage = Database\Webpage::fromDBwid($_GET['wid']);
- $lists = Database\ArchiveList::allListsByUser($user->UID);
}
catch (Exception $e) {}
?>
@@ -22,7 +20,7 @@
<form action="/list" method="GET">
<input type="hidden" name="method" value="PATCH">
<select name="lid">
- <?php foreach ($lists as $list): ?>
+ <?php foreach ($user->archiveLists() as $list): ?>
<option value="<?= $list->LID ?>"><?= $list->Name ?></option>
<?php endforeach; ?>
</select>
diff --git a/views/profile/index.php b/views/profile/index.php
index dad2070..0a10e4a 100644
--- a/views/profile/index.php
+++ b/views/profile/index.php
@@ -18,7 +18,7 @@
<h2 onclick="openArchives()">Archives</h2>
<h2 onclick="openLists()">Lists</h2>
<section id="user-archives">
- <?php foreach (Database\Webpage::allArchivesByUser($user->UID) as $page): ?>
+ <?php foreach ($user->archives() as $page): ?>
<section class="item">
<section>
<div>
@@ -51,7 +51,7 @@
</section>
<section id="user-lists" hidden>
- <?php foreach(Database\ArchiveList::allListsByUser($user->UID) as $list): ?>
+ <?php foreach($user->archiveLists() as $list): ?>
<section>
<?= $list->Name ?>
<?= $list->Description ?>