diff --git a/controllers/ConfirmDelete.php b/controllers/ConfirmDelete.php new file mode 100644 index 00000000..7f204232 --- /dev/null +++ b/controllers/ConfirmDelete.php @@ -0,0 +1,43 @@ +isLoggedIn()) + throw new NotAllowedException(); + + $photo = Asset::fromSlug($_GET['slug']); + if (empty($photo)) + throw new NotFoundException(); + + $author = $photo->getAuthor(); + if (!($user->isAdmin() || $user->getUserId() === $author->getUserId())) + throw new NotAllowedException(); + + if (isset($_REQUEST['confirmed'])) + $this->handleDelete($photo); + + parent::__construct('Confirm deletion' . ' - ' . SITE_TITLE); + $page = new ConfirmDeletePage($photo->getImage()); + + $this->page->adopt($page); + } + + private function handleDelete(Asset $photo) { + $album_url = $photo->getSubdir(); + + $photo->delete(); + + header('Location: ' . BASEURL . '/' . $album_url); + exit; + } +} diff --git a/models/Asset.php b/models/Asset.php index 6d15a094..62ee0aa1 100644 --- a/models/Asset.php +++ b/models/Asset.php @@ -485,6 +485,14 @@ class Asset if (!unlink(ASSETSDIR . '/' . $this->subdir . '/' . $this->filename)) return false; + $db->query(' + UPDATE tags + SET id_asset_thumb = 0 + WHERE id_asset_thumb = {int:id_asset} AND kind = "Album"', + [ + 'id_asset' => $this->id_asset, + ]); + $db->query(' DELETE FROM assets_meta WHERE id_asset = {int:id_asset}', diff --git a/models/Dispatcher.php b/models/Dispatcher.php index f9cc9307..7fb8bc69 100644 --- a/models/Dispatcher.php +++ b/models/Dispatcher.php @@ -28,6 +28,7 @@ class Dispatcher 'suggest' => 'ProvideAutoSuggest', 'timeline' => 'ViewTimeline', 'uploadmedia' => 'UploadMedia', + 'confirmdelete' => 'ConfirmDelete', ]; // Work around PHP's FPM not always providing PATH_INFO. diff --git a/public/css/default.css b/public/css/default.css index 736b9747..a41421e0 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -629,6 +629,14 @@ a#previous_photo:hover, a#next_photo:hover { width: 20%; } +#confirm_box { + background: #fff; + box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); + padding: 2%; + margin: 25px 0 25px 0; + text-align: center; +} + /* Responsive: smartphone in portrait ---------------------------------------*/ diff --git a/templates/ConfirmDeletePage.php b/templates/ConfirmDeletePage.php new file mode 100644 index 00000000..2b003a69 --- /dev/null +++ b/templates/ConfirmDeletePage.php @@ -0,0 +1,52 @@ +photo = $photo; + } + + protected function html_content() + { + $this->confirm(); + $this->photo(); + } + + private function confirm() + { + echo ' +
'; + } + + private function photo() + { + echo ' + '; + } +} diff --git a/templates/EditAssetForm.php b/templates/EditAssetForm.php index 14e29f8f..0fbf89a0 100644 --- a/templates/EditAssetForm.php +++ b/templates/EditAssetForm.php @@ -23,7 +23,7 @@ class EditAssetForm extends SubTemplate