forked from Public/pics
Adds a Confirm Delete page and actually delete the assets.
This commit is contained in:
parent
344db6e4c5
commit
e40c05c1f8
43
controllers/ConfirmDelete.php
Normal file
43
controllers/ConfirmDelete.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
/*****************************************************************************
|
||||||
|
* ConfirmDelete.php
|
||||||
|
* Contains the ConfirmDelete controller
|
||||||
|
*
|
||||||
|
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
class ConfirmDelete extends HTMLController
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Ensure we're logged in at this point.
|
||||||
|
$user = Registry::get('user');
|
||||||
|
if (!$user->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;
|
||||||
|
}
|
||||||
|
}
|
@ -485,6 +485,14 @@ class Asset
|
|||||||
if (!unlink(ASSETSDIR . '/' . $this->subdir . '/' . $this->filename))
|
if (!unlink(ASSETSDIR . '/' . $this->subdir . '/' . $this->filename))
|
||||||
return false;
|
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('
|
$db->query('
|
||||||
DELETE FROM assets_meta
|
DELETE FROM assets_meta
|
||||||
WHERE id_asset = {int:id_asset}',
|
WHERE id_asset = {int:id_asset}',
|
||||||
|
@ -28,6 +28,7 @@ class Dispatcher
|
|||||||
'suggest' => 'ProvideAutoSuggest',
|
'suggest' => 'ProvideAutoSuggest',
|
||||||
'timeline' => 'ViewTimeline',
|
'timeline' => 'ViewTimeline',
|
||||||
'uploadmedia' => 'UploadMedia',
|
'uploadmedia' => 'UploadMedia',
|
||||||
|
'confirmdelete' => 'ConfirmDelete',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Work around PHP's FPM not always providing PATH_INFO.
|
// Work around PHP's FPM not always providing PATH_INFO.
|
||||||
|
@ -629,6 +629,14 @@ a#previous_photo:hover, a#next_photo:hover {
|
|||||||
width: 20%;
|
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
|
/* Responsive: smartphone in portrait
|
||||||
---------------------------------------*/
|
---------------------------------------*/
|
||||||
|
52
templates/ConfirmDeletePage.php
Normal file
52
templates/ConfirmDeletePage.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/*****************************************************************************
|
||||||
|
* ConfirmDeletePage.php
|
||||||
|
* Contains the confirm delete page template.
|
||||||
|
*
|
||||||
|
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
class ConfirmDeletePage extends SubTemplate
|
||||||
|
{
|
||||||
|
private $photo;
|
||||||
|
|
||||||
|
public function __construct(Image $photo)
|
||||||
|
{
|
||||||
|
$this->photo = $photo;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function html_content()
|
||||||
|
{
|
||||||
|
$this->confirm();
|
||||||
|
$this->photo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function confirm()
|
||||||
|
{
|
||||||
|
echo '
|
||||||
|
<div id=confirm_box>
|
||||||
|
<h1>Confirm deletion</h1>
|
||||||
|
<p>You are about to permanently delete the following photo.</p>
|
||||||
|
<a class="btn btn-red" href="', BASEURL, '/confirmdelete?slug=', $this->photo->getSlug(), '&confirmed">Delete</a>
|
||||||
|
<a class="btn" href="', $this->photo->getPageUrl(), '"> Cancel</a>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function photo()
|
||||||
|
{
|
||||||
|
echo '
|
||||||
|
<div id="photo_frame">
|
||||||
|
<a href="', $this->photo->getUrl(), '">';
|
||||||
|
|
||||||
|
if ($this->photo->isPortrait())
|
||||||
|
echo '
|
||||||
|
<img src="', $this->photo->getThumbnailUrl(null, 960), '" alt="">';
|
||||||
|
else
|
||||||
|
echo '
|
||||||
|
<img src="', $this->photo->getThumbnailUrl(1280, null), '" alt="">';
|
||||||
|
|
||||||
|
echo '
|
||||||
|
</a>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ class EditAssetForm extends SubTemplate
|
|||||||
<form id="asset_form" action="" method="post" enctype="multipart/form-data">
|
<form id="asset_form" action="" method="post" enctype="multipart/form-data">
|
||||||
<div class="boxed_content" style="margin-bottom: 2%">
|
<div class="boxed_content" style="margin-bottom: 2%">
|
||||||
<div style="float: right">
|
<div style="float: right">
|
||||||
<a class="btn btn-red" href="', BASEURL, '/editasset/?id=', $this->asset->getId(), '&delete">Delete asset</a>
|
<a class="btn btn-red" href="', BASEURL, '/confirmdelete?slug=', $this->asset->getSlug(), '>Delete asset</a>
|
||||||
<input type="submit" value="Save asset data">
|
<input type="submit" value="Save asset data">
|
||||||
</div>
|
</div>
|
||||||
<h2>Edit asset \'', $this->asset->getTitle(), '\' (', $this->asset->getFilename(), ')</h2>
|
<h2>Edit asset \'', $this->asset->getTitle(), '\' (', $this->asset->getFilename(), ')</h2>
|
||||||
|
@ -198,7 +198,7 @@ class PhotoPage extends SubTemplate
|
|||||||
echo '
|
echo '
|
||||||
<div id=user_actions_box>
|
<div id=user_actions_box>
|
||||||
<h3>Actions</h3>
|
<h3>Actions</h3>
|
||||||
<a class="btn btn-red" href="', BASEURL, '/editasset/?id=', $this->photo->getId(), '&delete">Delete asset</a>
|
<a class="btn btn-red" href="', BASEURL, '/confirmdelete?slug=', $this->photo->getSlug(), '">Delete</a>
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user