PostController.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class PostController implements IController {
  3. public function execute() {
  4. $view = new View();
  5. $form = new Form();
  6. $postModel = new PostModel();
  7. $loginViewDecider = new LoginViewDecider();
  8. $topicModel = new TopicModel();
  9. $commentsRenderer = new CommentsRenderer();
  10. $permissionDecider = new PermissionDecider();
  11. $headRenderer = new HeadRenderer();
  12. $user = new User();
  13. $notificationScraper = new NotificationScraper();
  14. $user->populate();
  15. $postId = $form->getCleanDefaulted("id", 0);
  16. $topicId = $form->getCleanDefaulted("t", 0);
  17. $commentId = $form->getCleanDefaulted("cid", 0);
  18. $page = $form->getCleanDefaulted("p", 0);
  19. $currentPost = $postModel->getPost($postId);
  20. $taggedContent = $notificationScraper->replaceNotificationsWithLinks($currentPost['content']);
  21. $currentPost['content'] = htmlspecialchars_decode($taggedContent);
  22. $user->markPostViewed($postId);
  23. $defaultTopics = $topicModel->getUserTopics();
  24. $currentTopic = $topicModel->getCurrentTopic($topicId);
  25. $sql = sprintf("SELECT f.* FROM files f
  26. JOIN post_file_associations pfa ON f.file_id = pfa.file_id
  27. WHERE pfa.post_id = '%s'", $postId);
  28. $database = new Database();
  29. $fileData = $database->query($sql);
  30. foreach ($fileData as $index => $file) {
  31. $fileComponents = explode('.', $file['name']);
  32. $fileData[$index]['icon'] = $fileComponents[count($fileComponents) - 1];
  33. }
  34. $postViewData = array();
  35. $postViewData["header"] = $headRenderer->render();
  36. $postViewData["postData"] = $currentPost;
  37. $postViewData["fileData"] = $fileData;
  38. $postViewData["commentView"] = $commentsRenderer->getComments($postId, $commentId, $page);
  39. $postViewData['topicData'] = $currentTopic;
  40. $postViewData['topicAccess'] = $permissionDecider->hasTopicAccess($topicId);
  41. $postViewData['user'] = $user;
  42. return $view->render("postPageView.inc", $postViewData);
  43. }
  44. }