report.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. /**
  3. * MyBB 1.8
  4. * Copyright 2014 MyBB Group, All Rights Reserved
  5. *
  6. * Website: http://www.mybb.com
  7. * License: http://www.mybb.com/about/license
  8. *
  9. */
  10. define("IN_MYBB", 1);
  11. define('THIS_SCRIPT', 'report.php');
  12. $templatelist = "report,report_thanks,report_error,report_reasons,report_error_nomodal,forumdisplay_password_wrongpass,forumdisplay_password";
  13. require_once "./global.php";
  14. require_once MYBB_ROOT.'inc/functions_modcp.php';
  15. $lang->load("report");
  16. if(!$mybb->user['uid'])
  17. {
  18. error_no_permission();
  19. }
  20. $plugins->run_hooks("report_start");
  21. $report = array();
  22. $verified = false;
  23. $report_type = 'post';
  24. $error = $report_type_db = '';
  25. if(!empty($mybb->input['type']))
  26. {
  27. $report_type = htmlspecialchars_uni($mybb->get_input('type'));
  28. }
  29. $report_title = $lang->report_content;
  30. $report_string = "report_reason_{$report_type}";
  31. if(isset($lang->$report_string))
  32. {
  33. $report_title = $lang->$report_string;
  34. }
  35. $id = 0;
  36. if($report_type == 'post')
  37. {
  38. if($mybb->usergroup['canview'] == 0)
  39. {
  40. error_no_permission();
  41. }
  42. // Do we have a valid post?
  43. $post = get_post($mybb->get_input('pid', MyBB::INPUT_INT));
  44. if(!$post)
  45. {
  46. $error = $lang->sprintf($lang->error_invalid_report, $report_type);
  47. }
  48. else
  49. {
  50. $id = $post['pid'];
  51. $id2 = $post['tid'];
  52. $report_type_db = "(type = 'post' OR type = '')";
  53. $checkid = $post['uid'];
  54. // Check for a valid forum
  55. $forum = get_forum($post['fid']);
  56. if(!isset($forum['fid']))
  57. {
  58. $error = $lang->sprintf($lang->error_invalid_report, $report_type);
  59. }
  60. else
  61. {
  62. $verified = true;
  63. }
  64. // Password protected forums ......... yhummmmy!
  65. $id3 = $forum['fid'];
  66. check_forum_password($forum['parentlist']);
  67. }
  68. }
  69. else if($report_type == 'profile')
  70. {
  71. $user = get_user($mybb->get_input('pid', MyBB::INPUT_INT));
  72. if(!isset($user['uid']))
  73. {
  74. $error = $lang->sprintf($lang->error_invalid_report, $report_type);
  75. }
  76. else
  77. {
  78. $verified = true;
  79. $report_type_db = "type = 'profile'";
  80. $id2 = $id3 = 0; // We don't use these on the profile
  81. $id = $checkid = $user['uid']; // id is the profile user
  82. }
  83. }
  84. else if($report_type == 'reputation')
  85. {
  86. // Any member can report a reputation comment but let's make sure it exists first
  87. $query = $db->simple_select("reputation", "*", "rid = '".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
  88. if(!$db->num_rows($query))
  89. {
  90. $error = $lang->sprintf($lang->error_invalid_report, $report_type);
  91. }
  92. else
  93. {
  94. $verified = true;
  95. $reputation = $db->fetch_array($query);
  96. $id = $reputation['rid']; // id is the reputation id
  97. $id2 = $checkid = $reputation['adduid']; // id2 is the user who gave the comment
  98. $id3 = $reputation['uid']; // id3 is the user who received the comment
  99. $report_type_db = "type = 'reputation'";
  100. }
  101. }
  102. $permissions = user_permissions($checkid);
  103. if(empty($permissions['canbereported']))
  104. {
  105. $error = $lang->sprintf($lang->error_invalid_report, $report_type);
  106. }
  107. $plugins->run_hooks("report_type");
  108. // Check for an existing report
  109. if(!empty($report_type_db))
  110. {
  111. $query = $db->simple_select("reportedcontent", "*", "reportstatus != '1' AND id = '{$id}' AND {$report_type_db}");
  112. if($db->num_rows($query))
  113. {
  114. // Existing report
  115. $report = $db->fetch_array($query);
  116. $report['reporters'] = my_unserialize($report['reporters']);
  117. if($mybb->user['uid'] == $report['uid'] || is_array($report['reporters']) && in_array($mybb->user['uid'], $report['reporters']))
  118. {
  119. $error = $lang->success_report_voted;
  120. }
  121. }
  122. }
  123. $mybb->input['action'] = $mybb->get_input('action');
  124. if(empty($error) && $verified == true && $mybb->input['action'] == "do_report" && $mybb->request_method == "post")
  125. {
  126. verify_post_check($mybb->get_input('my_post_key'));
  127. $plugins->run_hooks("report_do_report_start");
  128. // Is this an existing report or a new offender?
  129. if(!empty($report))
  130. {
  131. // Existing report, add vote
  132. $report['reporters'][] = $mybb->user['uid'];
  133. update_report($report);
  134. $plugins->run_hooks("report_do_report_end");
  135. eval("\$report_thanks = \"".$templates->get("report_thanks")."\";");
  136. echo $report_thanks;
  137. exit;
  138. }
  139. else
  140. {
  141. // Bad user!
  142. $new_report = array(
  143. 'id' => $id,
  144. 'id2' => $id2,
  145. 'id3' => $id3,
  146. 'uid' => $mybb->user['uid']
  147. );
  148. // Figure out the reason
  149. $rid = $mybb->get_input('reason', MyBB::INPUT_INT);
  150. $query = $db->simple_select("reportreasons", "*", "rid = '{$rid}'");
  151. if(!$db->num_rows($query))
  152. {
  153. $error = $lang->sprintf($lang->error_invalid_report, $report_type);
  154. $verified = false;
  155. }
  156. else
  157. {
  158. $reason = $db->fetch_array($query);
  159. $new_report['reasonid'] = $reason['rid'];
  160. if($reason['extra'])
  161. {
  162. $comment = trim($mybb->get_input('comment'));
  163. if(empty($comment) || $comment == '')
  164. {
  165. $error = $lang->error_comment_required;
  166. $verified = false;
  167. }
  168. else
  169. {
  170. if(my_strlen($comment) < 3)
  171. {
  172. $error = $lang->error_report_length;
  173. $verified = false;
  174. }
  175. else
  176. {
  177. $new_report['reason'] = $comment;
  178. }
  179. }
  180. }
  181. }
  182. if(empty($error))
  183. {
  184. add_report($new_report, $report_type);
  185. $plugins->run_hooks("report_do_report_end");
  186. eval("\$report_thanks = \"".$templates->get("report_thanks")."\";");
  187. echo $report_thanks;
  188. exit;
  189. }
  190. }
  191. }
  192. if(!empty($error) || $verified == false)
  193. {
  194. $mybb->input['action'] = '';
  195. if($verified == false && empty($error))
  196. {
  197. $error = $lang->sprintf($lang->error_invalid_report, $report_type);
  198. }
  199. }
  200. if(!$mybb->input['action'])
  201. {
  202. if(!empty($error))
  203. {
  204. if($mybb->input['no_modal'])
  205. {
  206. eval("\$report_reasons = \"".$templates->get("report_error_nomodal")."\";");
  207. }
  208. else
  209. {
  210. eval("\$report_reasons = \"".$templates->get("report_error")."\";");
  211. }
  212. }
  213. else
  214. {
  215. if(!empty($report))
  216. {
  217. eval("\$report_reasons = \"".$templates->get("report_duplicate")."\";");
  218. }
  219. else
  220. {
  221. $reportreasons = $cache->read('reportreasons');
  222. $reasons = $reportreasons[$report_type];
  223. $reasonslist = '';
  224. foreach($reasons as $reason)
  225. {
  226. $reason['title'] = htmlspecialchars_uni($lang->parse($reason['title']));
  227. eval("\$reasonslist .= \"".$templates->get("report_reason")."\";");
  228. }
  229. eval("\$report_reasons = \"".$templates->get("report_reasons")."\";");
  230. }
  231. }
  232. if($mybb->input['no_modal'])
  233. {
  234. echo $report_reasons;
  235. exit;
  236. }
  237. $plugins->run_hooks("report_end");
  238. eval("\$report = \"".$templates->get("report", 1, 0)."\";");
  239. echo $report;
  240. exit;
  241. }