aboutsummaryrefslogtreecommitdiff
path: root/lib/functions.php
diff options
context:
space:
mode:
authorArno Richter <oelna@oelna.de>2022-12-13 23:28:38 +0100
committerArno Richter <oelna@oelna.de>2022-12-13 23:28:38 +0100
commit67b51e9f905c568444741eaad0eb5d82df7f09c8 (patch)
treeb7852e7d57e15a42f3dd752f891e8d513e3139a8 /lib/functions.php
parent0399f48a1f6a5e7151e3539038662686ed365ca7 (diff)
downloadmicroblog-67b51e9f905c568444741eaad0eb5d82df7f09c8.tar.gz
microblog-67b51e9f905c568444741eaad0eb5d82df7f09c8.tar.bz2
microblog-67b51e9f905c568444741eaad0eb5d82df7f09c8.zip
make pagination more robust. add undelete method for posts, if you know the id.
Diffstat (limited to 'lib/functions.php')
-rw-r--r--lib/functions.php10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/functions.php b/lib/functions.php
index 268808c..7046eb5 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -40,7 +40,7 @@ function db_insert($content, $timestamp=NOW) {
return $db->lastInsertId();
}
-function db_delete($post_id) {
+function db_delete($post_id, $undelete=false) {
global $db;
if(empty($db)) return false;
if(!is_numeric($post_id) || $post_id <= 0) return false;
@@ -50,10 +50,14 @@ function db_delete($post_id) {
$statement->bindParam(':id', $post_id, PDO::PARAM_INT);
*/
+ // delete or undelete/restore
+ $post_deleted = !$undelete ? time() : null;
+ $type = !$undelete ? PDO::PARAM_INT : PDO::PARAM_NULL;
+
// mark as deleted instead (for undo?!)
$statement = $db->prepare('UPDATE posts SET post_deleted = :post_deleted WHERE id = :id');
$statement->bindValue(':id', $post_id, PDO::PARAM_INT);
- $statement->bindValue(':post_deleted', time(), PDO::PARAM_INT);
+ $statement->bindValue(':post_deleted', $post_deleted, $type);
$statement->execute();
@@ -115,7 +119,7 @@ function db_posts_count() {
global $db;
if(empty($db)) return false;
- $statement = $db->prepare('SELECT COUNT(*) AS posts_count FROM posts');
+ $statement = $db->prepare('SELECT COUNT(*) AS posts_count FROM posts WHERE post_deleted IS NULL');
$statement->execute();
$row = $statement->fetch(PDO::FETCH_ASSOC);