SubmitEditPostController.inc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class SubmitEditPostController implements IController {
  3. public function execute() {
  4. $user = new User();
  5. $user->populate();
  6. if ($user->getId()) {
  7. $form = new Form();
  8. $postId = $form->getCleanDefaulted('id', 0);
  9. $topicId = $form->getCleanDefaulted('t', 0);
  10. $postContent = $form->postCleanDefaulted('postContent', '');
  11. $file = $form->file("attachment1");
  12. $userInputScrubber = new UserInputScrubber();
  13. $postContent = $userInputScrubber->scrubString($postContent);
  14. $sql = sprintf("UPDATE posts SET content = '%s' WHERE post_id = '%s' AND poster_user_id = '%s'",
  15. $postContent,
  16. $postId,
  17. $user->getId()
  18. );
  19. $database = new Database();
  20. $database->query($sql);
  21. $fileUploadHandler = new FileUploadHandler();
  22. $fileUploadHandler->saveFileToPost($file, $postId, $user->getId());
  23. $sql = "INSERT INTO post_last_updated (post_id, last_updated) VALUES (" . $postId . ", NOW())";
  24. $database->write($sql);
  25. $header = new Header();
  26. $header->redirect("?a=post&id=" .$postId. "&t=" . $topicId);
  27. }
  28. }
  29. }