diff --git a/src/classes/page.php b/src/classes/page.php
index 13529b7f..916cdf87 100644
--- a/src/classes/page.php
+++ b/src/classes/page.php
@@ -657,6 +657,50 @@ class Page
header();
+ $this->bodyStart();
+ $this->navigation();
+
+ $class = new \ReflectionClass($objectNotFound);
+ $className = $class->getShortName();
+ ?>
+
+
+
+
+ = $this->messages() ?>
+
+ ' . sprintf(__('The requested %s was not found and likely deleted by its creator.'), $className) . '';
+ break;
+
+ default:
+ echo '
' . sprintf(__('The requested %s was not found.'), $className) . '
';
+ break;
+ }
+ break;
+ }
+ ?>
+
+
+ footer();
+ $this->bodyEnd();
+
+ die();
+ }
+
public function messages(): string
{
$html = '';
diff --git a/src/classes/wish.php b/src/classes/wish.php
index 7f04be15..e77d86a9 100644
--- a/src/classes/wish.php
+++ b/src/classes/wish.php
@@ -49,6 +49,8 @@ class Wish
public \stdClass $info;
+ public bool $exists = false;
+
public function __construct(int|array $wish, bool $generateCache = false)
{
global $database;
@@ -68,26 +70,28 @@ class Wish
}
if ($columns) {
+ $this->exists = true;
+
foreach ($columns as $key => $value) {
$this->$key = $value;
}
- }
- $this->info = new \stdClass();
+ $this->info = new \stdClass();
- if ($this->url) {
- $this->cache = new EmbedCache($this->url);
- $this->info = $this->cache->get($generateCache);
- }
-
- foreach ($columns as $key => $value) {
- if (empty($value) && isset($this->info->$key)) {
- $this->$key = $this->info->$key;
+ if ($this->url) {
+ $this->cache = new EmbedCache($this->url);
+ $this->info = $this->cache->get($generateCache);
}
- }
- if (empty($this->image)) {
- $this->image = '/src/assets/img/no-image.svg';
+ foreach ($columns as $key => $value) {
+ if (empty($value) && isset($this->info->$key)) {
+ $this->$key = $this->info->$key;
+ }
+ }
+
+ if (empty($this->image)) {
+ $this->image = '/src/assets/img/no-image.svg';
+ }
}
}
@@ -202,10 +206,14 @@ class Wish
public function getTitle(): string
{
- $title = $this->title
- ?: $this->description
- ?: $this->url
- ?: $this->id;
+ $title = __('Wish not found');
+
+ if ($this->exists) {
+ $title = $this->title
+ ?: $this->description
+ ?: $this->url
+ ?: $this->id;
+ }
return $title;
}
diff --git a/src/classes/wishlist.php b/src/classes/wishlist.php
index 524c59ad..8f45d2e9 100644
--- a/src/classes/wishlist.php
+++ b/src/classes/wishlist.php
@@ -36,13 +36,12 @@ class Wishlist
WHERE `' . $column . '` = ' . $id_or_hash . ';')
->fetch();
- foreach ($columns as $key => $value) {
- $this->$key = $value;
- }
-
- /** Exists */
- if (isset($this->id)) {
+ if ($columns) {
$this->exists = true;
+
+ foreach ($columns as $key => $value) {
+ $this->$key = $value;
+ }
} else {
return;
}
@@ -109,4 +108,15 @@ class Wishlist
return $html;
}
+
+ public function getTitle(): string
+ {
+ $title = __('Wishlist not found');
+
+ if ($this->exists) {
+ $title = $this->name;
+ }
+
+ return $title;
+ }
}
diff --git a/src/pages/wish.php b/src/pages/wish.php
index 16da50c3..ebd87a7c 100644
--- a/src/pages/wish.php
+++ b/src/pages/wish.php
@@ -35,6 +35,10 @@ if ('POST' === $_SERVER['REQUEST_METHOD'] && count($_POST) >= 0) {
$page->messages[] = Page::success(__('Wish successfully updated.'), __('Success'));
}
+if (!$userIsAuthenticated || !$wish->exists) {
+ $page->errorDocument(404, $wish);
+}
+
$wishlists = $user->getWishlists($wish->wishlist);
foreach ($wishlists as $wishlist) {
@@ -44,15 +48,6 @@ foreach ($wishlists as $wishlist) {
}
}
-if (!$userIsAuthenticated) {
- http_response_code(404);
- ?>
-
= __('Not found') ?>
- = __('The requested Wish was not found.') ?>
- header();
$page->bodyStart();
$page->navigation();
diff --git a/src/pages/wishlist.php b/src/pages/wishlist.php
index e1a5665d..3caeb5b4 100644
--- a/src/pages/wishlist.php
+++ b/src/pages/wishlist.php
@@ -9,17 +9,12 @@
use wishthis\{Page, User, Wishlist};
$wishlist = new Wishlist($_GET['wishlist']);
+$page = new Page(__FILE__, $wishlist->getTitle());
if (!$wishlist->exists) {
- http_response_code(404);
- ?>
- = __('Not found') ?>
- = __('The requested Wishlist was not found and likely deleted by its creator.') ?>
- errorDocument(404, $wishlist);
}
-$page = new Page(__FILE__, $wishlist->name);
$page->header();
$page->bodyStart();
$page->navigation();