Posts
+Beiträge
= (substr($post['text'], 0, 512) !== $post['text']) ? '...Weiterlesen...' : '' ?> isLoggedIn()) return false; + if (!$this->canEditPost($id)) return false; + + $errors = array(); + + try { + $s = $this->pdo->prepare("DELETE FROM posts WHERE id = :id LIMIT 1;"); + $r = $s->execute(array( + ':id' => $id, + )); + if(!$r) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + } catch (\PDOException $e) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + + try { + $s = $this->pdo->prepare("DELETE FROM comments WHERE post = :id;"); + $r = $s->execute(array( + ':id' => $id, + )); + if(!$r) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + } catch (\PDOException $e) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + + if (count($errors) > 0) { + return $errors; + } + return true; + } + public function deleteUser($id) { + if (!$this->isLoggedIn()) return false; + if (!$this->hasRole([ \Bloggr\Roles::ADMIN ])) { + return false; + } + + $errors = array(); + + try { + $s = $this->pdo->prepare("DELETE FROM users WHERE id = :id;"); + $r = $s->execute(array( + ':id' => $id, + )); + if(!$r) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + } catch (\PDOException $e) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + + try { + $s = $this->pdo->prepare("DELETE FROM posts WHERE user = :id;"); + $r = $s->execute(array( + ':id' => $id, + )); + if(!$r) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + } catch (\PDOException $e) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + + try { + $s = $this->pdo->prepare("DELETE FROM comments WHERE user = :id;"); + $r = $s->execute(array( + ':id' => $id, + )); + if(!$r) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + } catch (\PDOException $e) { + array_push($errors, 'Da ist etwas schiefgelaufen!'); + } + if (count($errors) > 0) { + return $errors; + } + return true; + } public function getPost($id) { if (empty($id) || !\is_numeric($id)) { return false; diff --git a/post.php b/post.php index 5f75dc4..d743fc5 100644 --- a/post.php +++ b/post.php @@ -66,6 +66,16 @@ if ($action == 'edit' && isset($_POST['edit'])) { } } +if ($action == 'edit' && isset($_POST['delete'])) { + $result = $auth->removePost($_GET['edit']); + + if (is_array($result)) { + $errors = $result; + } else { + header("Location: /"); + } +} + if ($action == 'edit') { $result = $auth->getPost($_GET['edit']); if(!$result) { @@ -109,16 +119,15 @@ require_once(__DIR__."/inc/head.php");
= nl2br($data['text']) ?>