/assets/themes/foolz/foolfuuka-theme-fuuka/controller.php

https://github.com/FoolCode/FoolFuuka · PHP · 161 lines · 132 code · 23 blank · 6 comment · 24 complexity · f004bbfe34d9e5d01859f6930cc463ad MD5 · raw file

  1. <?php
  2. namespace Foolz\FoolFuuka\Themes\Fuuka\Controller;
  3. use Foolz\FoolFrame\Model\Cookie;
  4. use Foolz\FoolFrame\Model\Util;
  5. use Foolz\FoolFuuka\Model\Board;
  6. use Foolz\FoolFuuka\Model\Comment;
  7. use Foolz\Inet\Inet;
  8. use Symfony\Component\HttpFoundation\Response;
  9. class Chan extends \Foolz\FoolFuuka\Controller\Chan
  10. {
  11. public function radix_page($page = 1)
  12. {
  13. $options = [
  14. 'per_page' => 24,
  15. 'per_thread' => 5,
  16. 'order' => ($this->radix->archive ? 'by_thread' : 'by_post')
  17. ];
  18. return $this->latest($page, $options);
  19. }
  20. public function radix_gallery($page = 1)
  21. {
  22. return $this->action_404();
  23. }
  24. /**
  25. * @return bool
  26. */
  27. public function radix_submit()
  28. {
  29. // adapter
  30. if (!$this->getPost()) {
  31. return $this->error(_i('You aren\'t sending the required fields for creating a new message.'));
  32. }
  33. if (!$this->checkCsrfToken()) {
  34. return $this->error(_i('The security token wasn\'t found. Try resubmitting.'));
  35. }
  36. if ($this->getPost('reply_delete')) {
  37. foreach ($this->getPost('delete') as $idx => $doc_id) {
  38. try {
  39. $comments = Board::forge($this->getContext())
  40. ->getPost()
  41. ->setOptions('doc_id', $doc_id)
  42. ->setRadix($this->radix)
  43. ->getComments();
  44. $comment = current($comments);
  45. $comment = new Comment($this->getContext(), $comment);
  46. $comment->delete($this->getPost('delpass'));
  47. } catch (\Foolz\FoolFuuka\Model\BoardException $e) {
  48. return $this->error($e->getMessage(), 404);
  49. } catch (\Foolz\FoolFuuka\Model\CommentDeleteWrongPassException $e) {
  50. return $this->error($e->getMessage(), 404);
  51. }
  52. }
  53. $this->builder->createLayout('redirect')
  54. ->getParamManager()
  55. ->setParam('url', $this->uri->create([$this->radix->shortname, 'thread', $comment->comment->thread_num]));
  56. $this->builder->getProps()->addTitle(_i('Redirecting'));
  57. return new Response($this->builder->build());
  58. }
  59. if ($this->getPost('reply_report')) {
  60. foreach ($this->getPost('delete') as $idx => $doc_id) {
  61. try {
  62. $this->getContext()->getService('foolfuuka.report_collection')
  63. ->add(
  64. $this->radix,
  65. $doc_id,
  66. $this->getPost('KOMENTO'),
  67. Inet::ptod($this->getRequest()->getClientIp())
  68. );
  69. } catch (\Foolz\FoolFuuka\Model\ReportException $e) {
  70. return $this->error($e->getMessage(), 404);
  71. }
  72. }
  73. $this->builder->createLayout('redirect')
  74. ->getParamManager()
  75. ->setParam('url', $this->uri->create($this->radix->shortname.'/thread/'.$this->getPost('parent')));
  76. $this->builder->getProps()->addTitle(_i('Redirecting'));
  77. return new Response($this->builder->build());
  78. }
  79. // Determine if the invalid post fields are populated by bots.
  80. if (isset($post['name']) && mb_strlen($post['name'], 'utf-8') > 0) {
  81. return $this->error();
  82. }
  83. if (isset($post['reply']) && mb_strlen($post['reply'], 'utf-8') > 0) {
  84. return $this->error();
  85. }
  86. if (isset($post['email']) && mb_strlen($post['email'], 'utf-8') > 0) {
  87. return $this->error();
  88. }
  89. $data = [];
  90. $post = $this->getPost();
  91. if (isset($post['parent'])) {
  92. $data['thread_num'] = $post['parent'];
  93. }
  94. if (isset($post['NAMAE'])) {
  95. $data['name'] = $post['NAMAE'];
  96. $this->response->headers->setCookie(new Cookie($this->getContext(), 'reply_name', $data['name'], 60*60*24*30));
  97. }
  98. if (isset($post['MERU'])) {
  99. $data['email'] = $post['MERU'];
  100. $this->response->headers->setCookie(new Cookie($this->getContext(), 'reply_email', $data['email'], 60*60*24*30));
  101. }
  102. if (isset($post['subject'])) {
  103. $data['title'] = $post['subject'];
  104. }
  105. if (isset($post['KOMENTO'])) {
  106. $data['comment'] = $post['KOMENTO'];
  107. }
  108. if (isset($post['delpass'])) {
  109. // get the password needed for the reply field if it's not set yet
  110. if (!$post['delpass'] || strlen($post['delpass']) < 3) {
  111. $post['delpass'] = Util::randomString(7);
  112. }
  113. $data['delpass'] = $post['delpass'];
  114. }
  115. if (isset($post['reply_spoiler'])) {
  116. $data['spoiler'] = true;
  117. }
  118. if (isset($post['reply_postas'])) {
  119. $data['capcode'] = $post['reply_postas'];
  120. }
  121. if (isset($post['recaptcha_challenge_field']) && isset($post['recaptcha_response_field'])) {
  122. $data['recaptcha_challenge'] = $post['recaptcha_challenge_field'];
  123. $data['recaptcha_response'] = $post['recaptcha_response_field'];
  124. }
  125. $media = null;
  126. if ($this->getRequest()->files->count()) {
  127. try {
  128. $media = $this->media_factory->forgeFromUpload($this->getRequest(), $this->radix);
  129. $media->spoiler = isset($data['spoiler']) && $data['spoiler'];
  130. } catch (\Foolz\FoolFuuka\Model\MediaUploadNoFileException $e) {
  131. $media = null;
  132. } catch (\Foolz\FoolFuuka\Model\MediaUploadException $e) {
  133. return $this->error($e->getMessage());
  134. }
  135. }
  136. return $this->submit($data, $media);
  137. }
  138. }