Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

takereport.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?
  2. /*
  3. * This page handles the backend from when a user submits a report.
  4. * It checks for (in order):
  5. * 1. The usual POST injections, then checks that things.
  6. * 2. Things that are required by the report type are filled
  7. * ('1' in the report_fields array).
  8. * 3. Things that are filled are filled with correct things.
  9. * 4. That the torrent you're reporting still exists.
  10. *
  11. * Then it just inserts the report to the DB and increments the counter.
  12. */
  13. authorize();
  14. if (!is_number($_POST['torrentid'])) {
  15. error(404);
  16. } else {
  17. $TorrentID = $_POST['torrentid'];
  18. }
  19. if (!is_number($_POST['categoryid'])) {
  20. error(404);
  21. } else {
  22. $CategoryID = $_POST['categoryid'];
  23. }
  24. if (!isset($_POST['type'])) {
  25. error(404);
  26. } elseif (array_key_exists($_POST['type'], $Types[$CategoryID])) {
  27. $Type = $_POST['type'];
  28. $ReportType = $Types[$CategoryID][$Type];
  29. } elseif (array_key_exists($_POST['type'], $Types['master'])) {
  30. $Type = $_POST['type'];
  31. $ReportType = $Types['master'][$Type];
  32. } else {
  33. //There was a type but it wasn't an option!
  34. error(403);
  35. }
  36. foreach ($ReportType['report_fields'] as $Field => $Value) {
  37. if ($Value == '1') {
  38. if (empty($_POST[$Field])) {
  39. $Err = "You are missing a required field ($Field) for a ".$ReportType['title'].' report.';
  40. }
  41. }
  42. }
  43. if (!empty($_POST['sitelink'])) {
  44. if (preg_match_all('/'.TORRENT_REGEX.'/i', $_POST['sitelink'], $Matches)) {
  45. $ExtraIDs = implode(' ', $Matches[4]);
  46. if (in_array($TorrentID, $Matches[4])) {
  47. $Err = "The extra permalinks you gave included the link to the torrent you're reporting!";
  48. }
  49. } else {
  50. $Err = 'The permalink was incorrect. It should look like '.site_url().'torrents.php?torrentid=12345';
  51. }
  52. } else {
  53. $ExtraIDs = '';
  54. }
  55. if (!empty($_POST['link'])) {
  56. //resource_type://domain:port/filepathname?query_string#anchor
  57. // http:// www .foo.com /bar
  58. if (preg_match_all('/'.URL_REGEX.'/is', $_POST['link'], $Matches)) {
  59. $Links = implode(' ', $Matches[0]);
  60. } else {
  61. $Err = "The extra links you provided weren't links...";
  62. }
  63. } else {
  64. $Links = '';
  65. }
  66. if (!empty($_POST['image'])) {
  67. if (preg_match("/^(".IMAGE_REGEX.")( ".IMAGE_REGEX.")*$/is", trim($_POST['image']), $Matches)) {
  68. $Images = $Matches[0];
  69. } else {
  70. $Err = "The extra image links you provided weren't links to images...";
  71. }
  72. } else {
  73. $Images = '';
  74. }
  75. if (!empty($_POST['track'])) {
  76. if (preg_match('/([0-9]+( [0-9]+)*)|All/is', $_POST['track'], $Matches)) {
  77. $Tracks = $Matches[0];
  78. } else {
  79. $Err = 'Tracks should be given in a space-separated list of numbers with no other characters.';
  80. }
  81. } else {
  82. $Tracks = '';
  83. }
  84. if (!empty($_POST['extra'])) {
  85. $Extra = db_string($_POST['extra']);
  86. } else {
  87. $Err = 'As useful as blank reports are, could you be a tiny bit more helpful? (Leave a comment)';
  88. }
  89. $DB->query("
  90. SELECT GroupID
  91. FROM torrents
  92. WHERE ID = $TorrentID");
  93. if (!$DB->has_results()) {
  94. $Err = "A torrent with that ID doesn't exist!";
  95. }
  96. list($GroupID) = $DB->next_record();
  97. if (!empty($Err)) {
  98. error($Err);
  99. include(SERVER_ROOT.'/sections/reportsv2/report.php');
  100. die();
  101. }
  102. $DB->query("
  103. SELECT ID
  104. FROM reportsv2
  105. WHERE TorrentID = $TorrentID
  106. AND ReporterID = ".db_string($LoggedUser['ID'])."
  107. AND ReportedTime > '".time_minus(3)."'");
  108. if ($DB->has_results()) {
  109. header("Location: torrents.php?torrentid=$TorrentID");
  110. die();
  111. }
  112. $DB->query("
  113. INSERT INTO reportsv2
  114. (ReporterID, TorrentID, Type, UserComment, Status, ReportedTime, Track, Image, ExtraID, Link)
  115. VALUES
  116. (".db_string($LoggedUser['ID']).", $TorrentID, '".db_string($Type)."', '$Extra', 'New', NOW(), '".db_string($Tracks)."', '".db_string($Images)."', '".db_string($ExtraIDs)."', '".db_string($Links)."')");
  117. $ReportID = $DB->inserted_id();
  118. $DB->query("
  119. SELECT UserID
  120. FROM torrents
  121. WHERE ID = $TorrentID");
  122. list($UploaderID) = $DB->next_record();
  123. $DB->query("
  124. SELECT Name, NameRJ, NameJP
  125. FROM torrents_group
  126. WHERE ID = $GroupID");
  127. list($GroupNameEng, $GroupNameRJ, $GroupNameJP) = $DB->next_record();
  128. $GroupName = $GroupNameEng ? $GroupNameEng : ($GroupNameRJ ? $GroupNameRJ : $GroupNameJP);
  129. Misc::send_pm($UploaderID, 0, "Torrent Reported: $GroupName", "Your torrent, \"[url=".site_url()."torrents.php?torrentid=$TorrentID]".$GroupName."[/url]\", was reported for the reason \"".$ReportType['title']."\".\n\nThe reporter also said: \"$Extra\"\n\nIf you think this report was in error, please contact staff. Failure to challenge some types of reports in a timely manner will be regarded as a lack of defense and may result in the torrent being deleted.");
  130. $Cache->delete_value("reports_torrent_$TorrentID");
  131. $Cache->increment('num_torrent_reportsv2');
  132. header("Location: torrents.php?torrentid=$TorrentID");
  133. ?>