From 4f442b985558d5f6ab892083fd150875db7258f4 Mon Sep 17 00:00:00 2001 From: Yaya Laressa Date: Tue, 6 Jul 2021 09:36:26 +0700 Subject: [PATCH] Fix post() for category deleting Prinsipnya kan categori yang memiliki post baik itu publik atau draf harusnya tidak bisa dihapus. pada template view sudah dibatasi demikian, namun ketika saya mencoba secara langsung melalui link `/category/nama_category/delete` bisa terhapus meski category tersebut memiliki postingan. Dengan fix ini maka hal itu tidak akan terjadi. --- system/htmly.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/system/htmly.php b/system/htmly.php index e47c2de..565dcfe 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -1903,12 +1903,35 @@ get('/category/:category/delete', function ($category) { }); // Get deleted category data -post('/category/:category/delete', function () { +post('/category/:category/delete', function ($category) +{ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if ($proper && login()) { + if ($proper && login()) + { + $desc = get_category_info($category); + if (strtolower($category) !== 'uncategorized') + { + $desc = $desc[0]; + } $file = from($_REQUEST, 'file'); $destination = from($_GET, 'destination'); - delete_page($file, $destination); + if (get_categorycount($desc->md) == 0 && get_draftcount($desc->md) == 0) + { + delete_page($file, $destination); + } + else + { + if ($destination == 'post') + { + $redirect = site_url(); + header("Location: $redirect"); + } + else + { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } });