summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/quick.php19
-rw-r--r--core/helpers/dir.php2
-rw-r--r--core/js/quick.js6
-rw-r--r--core/models/item.php15
-rw-r--r--core/views/quick_pane.html.php4
5 files changed, 38 insertions, 8 deletions
diff --git a/core/controllers/quick.php b/core/controllers/quick.php
index b9a8fb82..20072044 100644
--- a/core/controllers/quick.php
+++ b/core/controllers/quick.php
@@ -93,6 +93,25 @@ class Quick_Controller extends Controller {
print json_encode(array("result" => "success"));
}
+ public function delete($id) {
+ access::verify_csrf();
+ $item = ORM::factory("item", $id);
+ access::required("edit", $item);
+
+ $parent = $item->parent();
+
+ if ($item->type == "album") {
+ $msg = t("Deleted album <b>%title</b>", array("title" => $item->title));
+ } else {
+ $msg = t("Deleted photo <b>%title</b>", array("title" => $item->title));
+ }
+
+ $item->delete();
+ message::success($msg);
+
+ print json_encode(array("result" => "success", "reload" => 1));
+ }
+
public function form_edit($id) {
$item = ORM::factory("item", $id);
access::required("edit", $item);
diff --git a/core/helpers/dir.php b/core/helpers/dir.php
index 33767f87..e9fe4ea7 100644
--- a/core/helpers/dir.php
+++ b/core/helpers/dir.php
@@ -27,7 +27,7 @@ class dir_Core {
} else if ($resource->isFile()) {
unlink($resource->getPathName());
} else if ($resource->isDir()) {
- directory::unlink($resource->getRealPath());
+ dir::unlink($resource->getRealPath());
}
unset($resource);
}
diff --git a/core/js/quick.js b/core/js/quick.js
index e662f77f..457b6d4a 100644
--- a/core/js/quick.js
+++ b/core/js/quick.js
@@ -49,6 +49,7 @@ var quick_do = function(cont, pane, img) {
dataType: "json",
success: function(data) {
img.css("opacity", "1");
+ cont.removeClass("gLoadingLarge");
if (data.src) {
img.attr("width", data.width);
img.attr("height", data.height);
@@ -58,8 +59,11 @@ var quick_do = function(cont, pane, img) {
} else {
img.css("margin-top", 0);
}
+ } else if (data.location) {
+ window.location = data.location;
+ } else if (data.reload) {
+ window.location.reload();
}
- cont.removeClass("gLoadingLarge");
}
});
}
diff --git a/core/models/item.php b/core/models/item.php
index e5e8c556..f78d50b3 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -85,16 +85,23 @@ class Item_Model extends ORM_MPTT {
}
public function delete() {
- $path = $this->file_path();
- parent::delete();
+ $original_path = $this->file_path();
+ $original_resize_path = $this->resize_path();
+ $original_thumb_path = $this->thumb_path();
+
// If there is no name, the path is invalid so don't try to delete
if (!empty($this->name)) {
if ($this->is_album()) {
- dir::unlink($path);
+ dir::unlink(dirname($original_path));
+ dir::unlink(dirname($original_resize_path));
+ dir::unlink(dirname($original_thumb_path));
} else {
- unlink($path);
+ unlink($original_path);
+ unlink($original_resize_path);
+ unlink($original_thumb_path);
}
}
+ parent::delete();
}
/**
diff --git a/core/views/quick_pane.html.php b/core/views/quick_pane.html.php
index 35c9dcf1..78a6c1ce 100644
--- a/core/views/quick_pane.html.php
+++ b/core/views/quick_pane.html.php
@@ -35,14 +35,14 @@
<?= t("Select as album cover") ?>
</span>
</a>
-<? endif ?>
-<a class="delete" href="#"
+<a class="delete" href="<?= url::site("quick/delete/$item->id?csrf=" . access::csrf_token()) ?>"
title="<?= t("Delete this item") ?>">
<span>
<?= t("Delete this item") ?>
</span>
</a>
+<? endif ?>
<a class="options" href="#"
title="<?= t("Additional options") ?>">