SubmitEditCommentController.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class SubmitEditCommentController implements IController {
  3. public function execute() {
  4. $form = new Form();
  5. $commentId = $form->getCleanDefaulted('id', 0);
  6. $content = $form->postCleanDefaulted('commentBody', "");
  7. $file = $form->file('attachment1');
  8. if ($content == "") {
  9. // attempt to delete?
  10. return;
  11. }
  12. if ($commentId == 0) {
  13. // no comment id specified, but this is an edit. wha?
  14. return;
  15. }
  16. $sql = sprintf("SELECT *
  17. FROM comments c
  18. JOIN comment_user_associations cu ON c.comment_id = cu.comment_id
  19. JOIN comment_post_associations cp ON c.comment_id = cp.comment_id
  20. JOIN post_topic_associations pt ON cp.post_id = pt.post_id
  21. WHERE c.comment_id = '%s'", $commentId);
  22. $database = new Database();
  23. $commentData = $database->query($sql);
  24. $commentData = $commentData[0];
  25. $user = new User();
  26. $user->populate();
  27. $userId = $user->getId();
  28. if ($userId == $commentData['user_id']) {
  29. $sql = sprintf("UPDATE comments SET content = '%s', is_edited = 1 WHERE comment_id = '%s'", $content, $commentId);
  30. $database->query($sql);
  31. $fileUploadHandler = new FileUploadHandler();
  32. $fileUploadHandler->saveFileToComment($file, $commentId, $userId);
  33. }
  34. $header = new Header();
  35. $header->redirect("/?a=post&id=" . $commentData['post_id'] . "&t=" . $commentData['topic_id']);
  36. }
  37. }