public function deleteAction() { if (!isset($_POST['comment_id'])) { return json_encode(["error" => "comment_id missing"]); } $comment_id = $_POST['comment_id']; CommentModel::delete($this->pdo, $comment_id); return json_encode(["message" => "Supprimé !", "comment_id" => $comment_id]); }
public function indexAction() { if (empty(explode('/', $_SERVER['REQUEST_URI'], 4)[2])) { header('Location: /'); exit; } else { $article_id = explode('/', $_SERVER['REQUEST_URI'], 4)[2]; } if (CommentModel::exists($this->pdo, $article_id)) { if ($_SESSION['auth']['username'] === CommentModel::getAuthor($this->pdo, $article_id) || $_SESSION['auth']['permissions'] === 'superadmin') { CommentModel::delete($this->pdo, $article_id); header('Location: /'); exit; } } else { header('Location: /404'); exit; } }
/** * Form to confirm that the administrator wants to delete the selected * comments (and has permission to do so). */ public function confirmCommentDeletes($DiscussionID = '') { $Session = Gdn::session(); $this->Form = new Gdn_Form(); $DiscussionModel = new DiscussionModel(); $Discussion = $DiscussionModel->getID($DiscussionID); if (!$Discussion) { return; } // Verify that the user has permission to perform the delete $PermissionCategory = CategoryModel::categories($Discussion->CategoryID); $this->permission('Vanilla.Comments.Delete', true, 'Category', val('PermissionCategoryID', $PermissionCategory)); $this->title(t('Confirm')); $CheckedComments = Gdn::userModel()->getAttribute($Session->User->UserID, 'CheckedComments', array()); if (!is_array($CheckedComments)) { $CheckedComments = array(); } $CommentIDs = array(); $DiscussionIDs = array(); foreach ($CheckedComments as $DiscID => $Comments) { foreach ($Comments as $Comment) { if (substr($Comment, 0, 11) == 'Discussion_') { $DiscussionIDs[] = str_replace('Discussion_', '', $Comment); } elseif ($DiscID == $DiscussionID) { $CommentIDs[] = str_replace('Comment_', '', $Comment); } } } $CountCheckedComments = count($CommentIDs); $this->setData('CountCheckedComments', $CountCheckedComments); if ($this->Form->authenticatedPostBack()) { // Delete the selected comments $CommentModel = new CommentModel(); foreach ($CommentIDs as $CommentID) { $CommentModel->delete($CommentID); } // Clear selections unset($CheckedComments[$DiscussionID]); Gdn::userModel()->saveAttribute($Session->UserID, 'CheckedComments', $CheckedComments); ModerationController::InformCheckedComments($this); $this->RedirectUrl = 'discussions'; } $this->render(); }
public function DeleteCommentAction() { $request = Project::getRequest(); $request_user_id = (int) Project::getUser()->getShowedUser()->id; $user = Project::getUser()->getDbUser(); $isAdmin = $user->user_type_id == 1 ? true : false; $user_id = (int) Project::getUser()->getDbUser()->id; $item_id = $request->getKeyByNumber(0); $comment_id = $request->getKeyByNumber(1); $item_name = $request->getKeyByNumber(2); $comment_model = new CommentModel($item_name . '_comment', $item_name . '_id', $comment_id); switch ($item_name) { case 'article': $item_model = new ArticleModel(); $item_controller = 'Article'; $item_action = 'ArticleView'; $item_name_id = $comment_model->article_id; break; case 'questions': $item_model = new QuestionModel(); $item_controller = 'QuestionAnswer'; $item_action = 'ViewQuestion'; $item_name_id = $comment_model->questions_id; break; case 'photo': $item_model = new PhotoModel(); $item_controller = 'Photo'; $item_action = 'View'; $item_name_id = $comment_model->photo_id; break; case 'bookmarks': $item_model = new BookmarksModel(); $item_controller = 'Bookmarks'; $item_action = 'BookmarksView'; $item_name_id = $comment_model->bookmarks_id; break; case 'social': $item_model = new SocialModel(); $item_controller = 'Social'; $item_action = 'SocialView'; $item_name_id = $comment_model->social_id; break; case 'blog': $item_model = new SocialModel(); $item_controller = 'Blog'; $item_action = 'Comments'; $item_name_id = $comment_model->blog_id; break; } $item_model->load($item_id); if ($comment_model->id > 0 && $item_model->id > 0 && $item_name_id == $item_model->id) { if ($comment_model->user_id == $user_id || $item_model->user_id == $user_id || $isAdmin) { $comment_model->delete($comment_model->user_id, $comment_id); $item_model->comments--; $item_model->save(); } } Project::getResponse()->redirect($request->createUrl($item_controller, $item_action, array($item_model->id))); }