EditPostController.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class EditPostController implements IController {
  3. public function execute() {
  4. $form = new Form();
  5. $postId = $form->getCleanDefaulted('id', 0);
  6. $topicId = $form->getCleanDefaulted('t', 0);
  7. $user = new User();
  8. $user->populate();
  9. $userId = $user->getId();
  10. $view = new View();
  11. $viewData = array();
  12. if ($userId) {
  13. $sql = sprintf("SELECT * FROM posts WHERE poster_user_id = '%s' AND post_id = '%s'", $userId, $postId);
  14. $database = new Database();
  15. $postData = $database->query($sql);
  16. $postData = $postData[0];
  17. $postData['content'] = htmlspecialchars_decode($postData['content']);
  18. if (! empty($postData)) {
  19. $headRenderer = new HeadRenderer();
  20. $topicModel = new TopicModel();
  21. $currentTopic = $topicModel->getCurrentTopic($topicId);
  22. $permissionDecider = new PermissionDecider();
  23. $sql = sprintf("SELECT f.* FROM files f
  24. JOIN post_file_associations pfa ON f.file_id = pfa.file_id
  25. WHERE pfa.post_id = '%s'", $postId);
  26. $database = new Database();
  27. $fileData = $database->query($sql);
  28. foreach($fileData as $index => $file) {
  29. $fileComponents = explode('.', $file['name']);
  30. $fileData[$index]['icon'] = $fileComponents[count($fileComponents)-1];
  31. }
  32. $viewData = array(
  33. 'header' => $headRenderer->render(),
  34. 'postData' => $postData,
  35. 'fileData' => $fileData,
  36. 'topicId' => $topicId,
  37. 'topicData' => $currentTopic,
  38. 'topicAccess' => $permissionDecider->hasTopicAccess($topicId),
  39. 'username' => $user->getDisplayName()
  40. );
  41. return $view->render('editPostView.inc', $viewData);
  42. }
  43. }
  44. // you must log in to view this page!
  45. }
  46. }