PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/takeedit.php

https://github.com/delete66/sikevux-s-tracker
PHP | 199 lines | 122 code | 34 blank | 43 comment | 86 complexity | 72b59fe327e4f188433656cfb71aa0b5 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @Author Neptune
  4. * @Credits All credit to Retro for the great idea of his updated modtask.php
  5. * @Project TBDev.net
  6. * @Category Addon Mods
  7. * @Date Monday, Jan 5, 2009
  8. */
  9. require 'include/bittorrent.php';
  10. require 'include/bbcode_functions.php';
  11. define('MIN_CLASS', UC_MODERATOR);
  12. define('NFO_SIZE', 65535);
  13. $possible_extensions = array('nfo', 'txt');
  14. if (!mkglobal('id:name:descr:type')) die();
  15. $id = 0 + $id;
  16. if(!is_valid_id($id))
  17. stderr('Error', 'Invalid ID!');
  18. dbconn();
  19. maxcoder();
  20. if(!logged_in())
  21. {
  22. header("HTTP/1.0 404 Not Found");
  23. // moddifed logginorreturn by retro//Remember to change the following line to match your server
  24. print("<html><h1>Not Found</h1><p>The requested URL /{$_SERVER['PHP_SELF']} was not found on this server.</p><hr /><address>Apache/1.1.11 (xxxxx) Server at ".$_SERVER['SERVER_NAME']." Port 80</address></body></html>\n");
  25. die();
  26. }
  27. /**
  28. * @Function valid_torrent_name
  29. * @Notes only safe characters are allowed..
  30. * @Begin
  31. */
  32. function valid_torrent_name($torrent_name) {
  33. $allowedchars = 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_';
  34. for ($i = 0; $i < strlen($torrent_name); ++$i)
  35. if (strpos($allowedchars, $torrent_name[$i]) === false)
  36. return false;
  37. return true;
  38. }
  39. /**
  40. * @Function valid_torrent_name
  41. * @Notes only safe characters are allowed..
  42. * @End
  43. */
  44. /**
  45. * @Function is_valid_url
  46. * @Begin
  47. */
  48. if (!function_exists('is_valid_url')) {
  49. function is_valid_url($link) {
  50. return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $link);
  51. }
  52. }
  53. /**
  54. * @Function is_valid_url
  55. * @End
  56. */
  57. $select_torrent = mysql_query('SELECT * FROM torrents WHERE id = ' . sqlesc($id)) or sqlerr(__FILE__, __LINE__);
  58. $fetch_assoc = mysql_fetch_assoc($select_torrent) or stderr('Error', 'No torrent with this ID!');
  59. if ($CURUSER['id'] != $fetch_assoc['owner'] && get_user_class() < MIN_CLASS)
  60. stderr('You\'re not the owner!', 'How did that happen?');
  61. $updateset = array();
  62. $fname = $fetch_assoc['filename'];
  63. preg_match('/^(.+)\.torrent$/si', $fname, $matches);
  64. $shortfname = $matches[1];
  65. $dname = $fetch_assoc['save_as'];
  66. if ((isset($_POST['nfoaction'])) && ($_POST['nfoaction'] == 'update')) {
  67. if (empty($_FILES['nfo']['name']))
  68. stderr('Updated failed', 'No NFO!');
  69. if ($_FILES['nfo']['size'] == 0)
  70. stderr('Updated failed', '0-byte NFO!');
  71. if (!preg_match('/^(.+)\.['.join(']|[', $possible_extensions).']$/si', $_FILES['nfo']['name']))
  72. stderr('Updated failed', 'Invalid extension. <b>' . join(', ', $possible_extensions).'</b> only!', FALSE);
  73. if (!empty($_FILES['nfo']['name']) && $_FILES['nfo']['size'] > NFO_SIZE)
  74. stderr('Updated failed', 'NFO is too big! Max ' . number_format(NFO_SIZE) . ' bytes!');
  75. if (@is_uploaded_file($_FILES['nfo']['tmp_name']) && @filesize($_FILES['nfo']['tmp_name']) > 0)
  76. $updateset[] = "nfo = " . sqlesc(str_replace("\x0d\x0d\x0a", "\x0d\x0a", file_get_contents($_FILES['nfo']['tmp_name'])));
  77. }
  78. else
  79. $updateset[] = 'nfo = ""';
  80. // Make sure they do not forget to fill these fields :D
  81. foreach(explode('||',"$descr||$type||$name") as $cannotbeblank) {
  82. if (empty($cannotbeblank))
  83. stderr('Updated failed', 'Missing form data!');
  84. }
  85. // Make sure they do not forget to fill these fields :D
  86. if(isset($_POST['name']) && (($name = $_POST['name']) != $fetch_assoc['name']) && valid_torrent_name($name))
  87. $updateset[] = 'name = ' . sqlesc($name);
  88. $updateset[] = 'search_text = ' . sqlesc(searchfield("$shortfname $dname $torrent"));
  89. if(isset($_POST['descr']) && ($descr = $_POST['descr']) != $fetch_assoc['descr'])
  90. $updateset[] = 'descr = ' . sqlesc($descr);
  91. $updateset[] = 'ori_descr = ' . sqlesc($descr);
  92. if(isset($_POST['type']) && (($category = 0 + $_POST['type']) != $fetch_assoc['category']) && is_valid_id($category))
  93. $updateset[] = 'category = ' . sqlesc($category);
  94. if(($visible = ($_POST['visible'] != ''?'yes':'no')) != $fetch_assoc['visible'])
  95. $updateset[] = 'visible = ' . sqlesc($visible);
  96. /**
  97. * @Custom Mods
  98. * @Notes Uncomment the mods you want..
  99. */
  100. //==Sticky torrents by tony
  101. if(($sticky = ($_POST['sticky'] != ''?'yes':'no')) != $fetch_assoc['sticky'])
  102. $updateset[] = 'sticky = ' . sqlesc($sticky);
  103. //==Simple nuke/reason mod by BIGBOSS
  104. if(isset($_POST['nuked']) && ($nuked = $_POST['nuked']) != $fetch_assoc['nuked'])
  105. $updateset[] = 'nuked = ' . sqlesc($nuked);
  106. if(isset($_POST['nukereason']) && ($nukereason = $_POST['nukereason']) != $fetch_assoc['nukereason'])
  107. $updateset[] = 'nukereason = ' . sqlesc($nukereason);
  108. //== Poster Mod by johim and EnzoF1
  109. if(isset($_POST['poster']) && (($poster = $_POST['poster']) != $fetch_assoc['poster'] && !empty($poster)))
  110. if (!preg_match("/^http:\/\/[^\s'\"<>]+\.(jpg|gif|png)$/i", $poster))
  111. stderr('Updated failed', 'Poster MUST be in jpg, gif or png format. Make sure you include http:// in the URL.');
  112. $updateset[] = 'poster = ' . sqlesc($poster);
  113. //==Genre Mod without mysql table by Traffic
  114. $genreaction = $_POST['genre'];
  115. if ($genreaction != "keep") {
  116. if (isset($_POST["music"]))
  117. $genre = implode(",", $_POST['music']);
  118. elseif (isset($_POST["movie"]))
  119. $genre = implode(",", $_POST['movie']);
  120. elseif (isset($_POST["game"]))
  121. $genre = implode(",", $_POST['game']);
  122. $updateset[] = "newgenre = " .sqlesc($genre);
  123. }
  124. if(($recommended = isset($_POST['recommended']) ? ($_POST['recommended'] == 'yes' ? 'yes' : 'no') : 'no') != $fetch_assoc['recommended'])
  125. $updateset[] = 'recommended = ' . sqlesc($recommended);
  126. //===count stats / free download
  127. if ((isset($_POST['countstats'])) && (($countstats = $_POST['countstats']) != $row['countstats'])){
  128. if(get_user_class() >= UC_MODERATOR)
  129. $updateset[] = "countstats = " . sqlesc($countstats);
  130. }
  131. else
  132. $updateset[] = "countstats = 'yes'";
  133. //==vip
  134. if(($vip = ($_POST['vip'] == 1?'yes':'no')) != $fetch_assoc['vip'])
  135. $updateset[] = 'vip = ' . sqlesc($vip);
  136. //==Requested & Released Type by dokty
  137. if(($scene = ($_POST['scene'] == 'no'?'no':'yes')) != $fetch_assoc['scene'])
  138. $updateset[] = 'scene = ' . sqlesc($scene);
  139. if(($request = ($_POST['request'] == 'no'?'no':'yes')) != $fetch_assoc['request'])
  140. $updateset[] = 'request = ' . sqlesc($request);
  141. /////////////////////imdb mod///////////////////
  142. if(isset($_POST['url']) && (($url = $_POST['url']) != $fetch_assoc['url'] && !empty($url)))
  143. if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url))
  144. stderr('Updated failed', 'Make sure you include http:// in the URL.');
  145. $updateset[] = 'url = ' . sqlesc($url);
  146. /////////////////////utube mod///////////////////
  147. if(isset($_POST['tube']) && (($tube = $_POST['tube']) != $fetch_assoc['tube'] && !empty($tube)))
  148. if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $tube))
  149. stderr('Updated failed', 'Make sure you include http:// in the URL.');
  150. $updateset[] = 'tube = ' . sqlesc($tube);
  151. //==Anonymous mod
  152. if(($anonymous = ($_POST['anonymous'] != ''?'yes':'no')) != $fetch_assoc['anonymous'])
  153. $updateset[] = 'anonymous = ' . sqlesc($anonymous);
  154. /////////////torrent mulplier//////////////
  155. if(get_user_class() >= UC_ADMINISTRATOR)
  156. $multiplicator = (isset($_POST['multiplicator']) ? $_POST['multiplicator'] : '');
  157. $valid_inputs = array(2,3,4,5);
  158. $multiplicator = (($multiplicator && in_array($multiplicator,$valid_inputs)) ? $multiplicator : 0);
  159. if($multiplicator != $fetch_assoc['multiplicator'])
  160. $updateset[] = 'multiplicator = ' . sqlesc($multiplicator);
  161. mysql_query('UPDATE torrents SET ' . implode(',', $updateset) . ' WHERE id = ' . sqlesc($id)) or sqlerr(__FILE__, __LINE__);
  162. write_log(htmlspecialchars($name) . ' was edited by ' . (($fetch_assoc['anonymous'] == 'yes') ? 'Anonymous' : htmlspecialchars($CURUSER['username'])));
  163. $returl = (isset($_POST['returnto']) ? '&returnto=' . urlencode($_POST['returnto']) : 'details.php?id=' . $id . '&edited=1');
  164. header("Refresh: 0; url=$returl");
  165. ?>