PageRenderTime 24ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/include/bittorrent.php

https://bitbucket.org/nexea/x00n
PHP | 794 lines | 666 code | 95 blank | 33 comment | 148 complexity | d52609a84fd6b401ac15e4f9f7a65972 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. error_reporting(E_ALL ^ E_NOTICE);
  3. require_once("include/cleanup.php");
  4. require_once("lib/db.php");
  5. if( !defined("x00n") )
  6. {
  7. header("Location: ./install/index.php");
  8. exit;
  9. }
  10. if (file_exists('install'))
  11. {
  12. die('Delete the install directory');
  13. }
  14. function local_user()
  15. {
  16. global $HTTP_SERVER_VARS;
  17. return $HTTP_SERVER_VARS["SERVER_ADDR"] == $HTTP_SERVER_VARS["REMOTE_ADDR"];
  18. }
  19. dbconn();
  20. $sql = "SELECT * FROM config";
  21. if( !($result = mysql_query($sql)) )
  22. {
  23. die("Could not query config information");
  24. }
  25. //THIS SETS UP OUR CONFIG VARIABLES FROM THE CONFIG TABLE
  26. while ( $row = mysql_fetch_assoc($result) )
  27. {
  28. $config[$row['name']] = $row['value'];
  29. }
  30. $FUNDS = $config['funds'];
  31. $SITE_ONLINE = $config['siteonline'];
  32. # the first one will be displayed on the pages
  33. $announce_urls = array();
  34. $announce_urls[] = $config['announce_url'];
  35. //set this to true to make this a tracker that only registered users may use
  36. $MEMBERSONLY = true;
  37. //maximum number of peers (seeders+leechers) allowed before torrents starts to be deleted to make room...
  38. //set this to something high if you don't require this feature
  39. $PEERLIMIT = $config['peerlimit'];
  40. // Email for sender/return path.
  41. $SITEEMAIL = $config['sitemail'];
  42. $SITENAME = $config['sitename'];
  43. // Set this to your site URL... No ending slash!
  44. $DEFAULTBASEURL = $config['domain'];
  45. $max_torrent_size = 1000000;
  46. $announce_interval = 60 * 30;
  47. $signup_timeout = 86400 * 3;
  48. $minvotes = 1;
  49. $max_dead_torrent_time = 6 * 3600;
  50. // Max users on site
  51. $maxusers = 75000;
  52. $torrent_dir = "torrents"; # must be writable for httpd user
  53. if ($HTTP_SERVER_VARS["HTTP_HOST"] == "")
  54. $HTTP_SERVER_VARS["HTTP_HOST"] = $HTTP_SERVER_VARS["SERVER_NAME"];
  55. $BASEURL = "http://" . $HTTP_SERVER_VARS["HTTP_HOST"];
  56. $autoclean_interval = 900;
  57. $pic_base_url = "images/";
  58. /**** validip/getip courtesy of manolete <manolete@myway.com> ****/
  59. // IP Validation
  60. function validip($ip)
  61. {
  62. if (!empty($ip) && ip2long($ip)!=-1)
  63. {
  64. // reserved IANA IPv4 addresses
  65. // http://www.iana.org/assignments/ipv4-address-space
  66. $reserved_ips = array (
  67. array('0.0.0.0','2.255.255.255'),
  68. array('10.0.0.0','10.255.255.255'),
  69. array('127.0.0.0','127.255.255.255'),
  70. array('169.254.0.0','169.254.255.255'),
  71. array('172.16.0.0','172.31.255.255'),
  72. array('192.0.2.0','192.0.2.255'),
  73. array('192.168.0.0','192.168.255.255'),
  74. array('255.255.255.0','255.255.255.255')
  75. );
  76. foreach ($reserved_ips as $r)
  77. {
  78. $min = ip2long($r[0]);
  79. $max = ip2long($r[1]);
  80. if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
  81. }
  82. return true;
  83. }
  84. else return false;
  85. }
  86. // Patched function to detect REAL IP address if it's valid
  87. function getip() {
  88. if (isset($_SERVER)) {
  89. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  90. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  91. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  92. $ip = $_SERVER['HTTP_CLIENT_IP'];
  93. } else {
  94. $ip = $_SERVER['REMOTE_ADDR'];
  95. }
  96. } else {
  97. if (getenv('HTTP_X_FORWARDED_FOR')) {
  98. $ip = getenv('HTTP_X_FORWARDED_FOR');
  99. } elseif (getenv('HTTP_CLIENT_IP')) {
  100. $ip = getenv('HTTP_CLIENT_IP');
  101. } else {
  102. $ip = getenv('REMOTE_ADDR');
  103. }
  104. }
  105. return $ip;
  106. }
  107. function userlogin() {
  108. global $HTTP_SERVER_VARS, $SITE_ONLINE;
  109. unset($GLOBALS["CURUSER"]);
  110. $ip = getip();
  111. $nip = ip2long($ip);
  112. $res = mysql_query("SELECT * FROM bans WHERE $nip >= first AND $nip <= last") or mysql_error();
  113. if (mysql_num_rows($res) > 0)
  114. {
  115. header("HTTP/1.0 403 Forbidden");
  116. print("<html><body><h1>403 Forbidden</h1>Unauthorized IP address.</body></html>\n");
  117. die;
  118. }
  119. if (!$SITE_ONLINE || empty($_COOKIE["uid"]) || empty($_COOKIE["pass"]))
  120. return;
  121. $id = 0 + $_COOKIE["uid"];
  122. if (!$id || strlen($_COOKIE["pass"]) != 32)
  123. return;
  124. $res = mysql_query("SELECT * FROM users WHERE id = $id AND enabled='yes' AND status = 'confirmed'");// or die(mysql_error());
  125. $row = mysql_fetch_array($res);
  126. if (!$row)
  127. return;
  128. $sec = hash_pad($row["secret"]);
  129. if ($_COOKIE["pass"] !== $row["passhash"])
  130. return;
  131. mysql_query("UPDATE users SET last_access='" . get_date_time() . "', ip='$ip' WHERE id=" . $row["id"]);// or die(mysql_error());
  132. $row['ip'] = $ip;
  133. $GLOBALS["CURUSER"] = $row;
  134. }
  135. function autoclean() {
  136. global $autoclean_interval;
  137. $now = time();
  138. $docleanup = 0;
  139. $res = mysql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime'");
  140. $row = mysql_fetch_array($res);
  141. if (!$row) {
  142. mysql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime',$now)");
  143. return;
  144. }
  145. $ts = $row[0];
  146. if ($ts + $autoclean_interval > $now)
  147. return;
  148. mysql_query("UPDATE avps SET value_u=$now WHERE arg='lastcleantime' AND value_u = $ts");
  149. if (!mysql_affected_rows())
  150. return;
  151. docleanup();
  152. }
  153. function unesc($x) {
  154. if (get_magic_quotes_gpc())
  155. return stripslashes($x);
  156. return $x;
  157. }
  158. function mksize($bytes)
  159. {
  160. if ($bytes < 1000 * 1024)
  161. return number_format($bytes / 1024, 2) . " kB";
  162. elseif ($bytes < 1000 * 1048576)
  163. return number_format($bytes / 1048576, 2) . " MB";
  164. elseif ($bytes < 1000 * 1073741824)
  165. return number_format($bytes / 1073741824, 2) . " GB";
  166. else
  167. return number_format($bytes / 1099511627776, 2) . " TB";
  168. }
  169. function mksizeint($bytes)
  170. {
  171. $bytes = max(0, $bytes);
  172. if ($bytes < 1000)
  173. return floor($bytes) . " B";
  174. elseif ($bytes < 1000 * 1024)
  175. return floor($bytes / 1024) . " kB";
  176. elseif ($bytes < 1000 * 1048576)
  177. return floor($bytes / 1048576) . " MB";
  178. elseif ($bytes < 1000 * 1073741824)
  179. return floor($bytes / 1073741824) . " GB";
  180. else
  181. return floor($bytes / 1099511627776) . " TB";
  182. }
  183. function deadtime() {
  184. global $announce_interval;
  185. return time() - floor($announce_interval * 1.3);
  186. }
  187. function mkprettytime($s) {
  188. if ($s < 0)
  189. $s = 0;
  190. $t = array();
  191. foreach (array("60:sec","60:min","24:hour","0:day") as $x) {
  192. $y = explode(":", $x);
  193. if ($y[0] > 1) {
  194. $v = $s % $y[0];
  195. $s = floor($s / $y[0]);
  196. }
  197. else
  198. $v = $s;
  199. $t[$y[1]] = $v;
  200. }
  201. if ($t["day"])
  202. return $t["day"] . "d " . sprintf("%02d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
  203. if ($t["hour"])
  204. return sprintf("%d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
  205. // if ($t["min"])
  206. return sprintf("%d:%02d", $t["min"], $t["sec"]);
  207. // return $t["sec"] . " secs";
  208. }
  209. function mkglobal($vars) {
  210. if (!is_array($vars))
  211. $vars = explode(":", $vars);
  212. foreach ($vars as $v) {
  213. if (isset($_GET[$v]))
  214. $GLOBALS[$v] = unesc($_GET[$v]);
  215. elseif (isset($_POST[$v]))
  216. $GLOBALS[$v] = unesc($_POST[$v]);
  217. else
  218. return 0;
  219. }
  220. return 1;
  221. }
  222. function tr($x,$y,$noesc=0) {
  223. if ($noesc)
  224. $a = $y;
  225. else {
  226. $a = htmlspecialchars($y);
  227. $a = str_replace("\n", "<br />\n", $a);
  228. }
  229. print("<tr><td class=\"heading\" valign=\"top\" align=\"right\">$x</td><td valign=\"top\" align=\"left\">$a</td></tr>\n");
  230. }
  231. function validfilename($name) {
  232. return preg_match('/^[^\0-\x1f:\\\\\/?*\xff#<>|]+$/si', $name);
  233. }
  234. function validemail($email) {
  235. return preg_match('/^[\w.-]+@([\w.-]+\.)+[a-z]{2,6}$/is', $email);
  236. }
  237. function sqlesc($x) {
  238. return "'".mysql_real_escape_string($x)."'";
  239. }
  240. function sqlwildcardesc($x) {
  241. return str_replace(array("%","_"), array("\\%","\\_"), mysql_real_escape_string($x));
  242. }
  243. function urlparse($m) {
  244. $t = $m[0];
  245. if (preg_match(',^\w+://,', $t))
  246. return "<a href=\"$t\">$t</a>";
  247. return "<a href=\"http://$t\">$t</a>";
  248. }
  249. function parsedescr($d, $html) {
  250. if (!$html)
  251. {
  252. $d = htmlspecialchars($d);
  253. $d = str_replace("\n", "\n<br>", $d);
  254. }
  255. return $d;
  256. }
  257. include('include/nav.php');
  258. function genbark($x,$y) {
  259. stdhead($y);
  260. print("<h2>" . htmlspecialchars($y) . "</h2>\n");
  261. print("<p>" . htmlspecialchars($x) . "</p>\n");
  262. stdfoot();
  263. exit();
  264. }
  265. function mksecret($len = 20) {
  266. $ret = "";
  267. for ($i = 0; $i < $len; $i++)
  268. $ret .= chr(mt_rand(0, 255));
  269. return $ret;
  270. }
  271. function httperr($code = 404) {
  272. header("HTTP/1.0 404 Not found");
  273. print("<h1>Not Found</h1>\n");
  274. print("<p>Sorry pal :(</p>\n");
  275. exit();
  276. }
  277. function gmtime()
  278. {
  279. return strtotime(get_date_time());
  280. }
  281. function logincookie($id, $passhash, $updatedb = 1, $expires = 0x7fffffff)
  282. {
  283. setcookie("uid", $id, time()+3600, "/" , ".x00n.com");
  284. setcookie("pass", $passhash, time()+3600 , "/", ".x00n.com");
  285. if ($updatedb)
  286. mysql_query("UPDATE users SET last_login = NOW() WHERE id = $id");
  287. }
  288. function logoutcookie() {
  289. setcookie("uid", "", time()-3600, "/" , ".x00n.com");
  290. setcookie("pass", "", time()-3600 , "/", ".x00n.com");
  291. }
  292. function allowedLogin(){
  293. }
  294. function loggedinorreturn() {
  295. global $CURUSER;
  296. if (!$CURUSER) {
  297. header("Location: http://www.x00n.com/index.php?action=login&returnto=" . urlencode($_SERVER["REQUEST_URI"]));
  298. exit();
  299. }
  300. }
  301. function deletetorrent($id) {
  302. global $torrent_dir;
  303. mysql_query("DELETE FROM torrents WHERE id = $id");
  304. foreach(explode(".","peers.files.comments.ratings") as $x)
  305. mysql_query("DELETE FROM $x WHERE torrent = $id");
  306. unlink("$torrent_dir/$id.torrent");
  307. }
  308. function pager($rpp, $count, $href, $opts = array()) {
  309. $pages = ceil($count / $rpp);
  310. if (!$opts["lastpagedefault"])
  311. $pagedefault = 0;
  312. else {
  313. $pagedefault = floor(($count - 1) / $rpp);
  314. if ($pagedefault < 0)
  315. $pagedefault = 0;
  316. }
  317. if (isset($_GET["page"])) {
  318. $page = 0 + $_GET["page"];
  319. if ($page < 0)
  320. $page = $pagedefault;
  321. }
  322. else
  323. $page = $pagedefault;
  324. $pager = "";
  325. $mp = $pages - 1;
  326. $as = "<b>&lt;&lt;&nbsp;Prev</b>";
  327. if ($page >= 1) {
  328. $pager .= "<a href=\"{$href}page=" . ($page - 1) . "\">";
  329. $pager .= $as;
  330. $pager .= "</a>";
  331. }
  332. else
  333. $pager .= $as;
  334. $pager .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  335. $as = "<b>Next&nbsp;&gt;&gt;</b>";
  336. if ($page < $mp && $mp >= 0) {
  337. $pager .= "<a href=\"{$href}page=" . ($page + 1) . "\">";
  338. $pager .= $as;
  339. $pager .= "</a>";
  340. }
  341. else
  342. $pager .= $as;
  343. if ($count) {
  344. $pagerarr = array();
  345. $dotted = 0;
  346. $dotspace = 3;
  347. $dotend = $pages - $dotspace;
  348. $curdotend = $page - $dotspace;
  349. $curdotstart = $page + $dotspace;
  350. for ($i = 0; $i < $pages; $i++) {
  351. if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend)) {
  352. if (!$dotted)
  353. $pagerarr[] = "...";
  354. $dotted = 1;
  355. continue;
  356. }
  357. $dotted = 0;
  358. $start = $i * $rpp + 1;
  359. $end = $start + $rpp - 1;
  360. if ($end > $count)
  361. $end = $count;
  362. $text = "$start&nbsp;-&nbsp;$end";
  363. if ($i != $page)
  364. $pagerarr[] = "<a href=\"{$href}page=$i\"><b>$text</b></a>";
  365. else
  366. $pagerarr[] = "<b>$text</b>";
  367. }
  368. $pagerstr = join(" | ", $pagerarr);
  369. $pagertop = "<p align=\"center\">$pager<br />$pagerstr</p>\n";
  370. $pagerbottom = "<p align=\"center\">$pagerstr<br />$pager</p>\n";
  371. }
  372. else {
  373. $pagertop = "<p align=\"center\">$pager</p>\n";
  374. $pagerbottom = $pagertop;
  375. }
  376. $start = $page * $rpp;
  377. return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
  378. }
  379. function downloaderdata($res) {
  380. $rows = array();
  381. $ids = array();
  382. $peerdata = array();
  383. while ($row = mysql_fetch_assoc($res)) {
  384. $rows[] = $row;
  385. $id = $row["id"];
  386. $ids[] = $id;
  387. $peerdata[$id] = array(downloaders => 0, seeders => 0, comments => 0);
  388. }
  389. if (count($ids)) {
  390. $allids = implode(",", $ids);
  391. $res = mysql_query("SELECT COUNT(*) AS c, torrent, seeder FROM peers WHERE torrent IN ($allids) GROUP BY torrent, seeder");
  392. while ($row = mysql_fetch_assoc($res)) {
  393. if ($row["seeder"] == "yes")
  394. $key = "seeders";
  395. else
  396. $key = "downloaders";
  397. $peerdata[$row["torrent"]][$key] = $row["c"];
  398. }
  399. $res = mysql_query("SELECT COUNT(*) AS c, torrent FROM comments WHERE torrent IN ($allids) GROUP BY torrent");
  400. while ($row = mysql_fetch_assoc($res)) {
  401. $peerdata[$row["torrent"]]["comments"] = $row["c"];
  402. }
  403. }
  404. return array($rows, $peerdata);
  405. }
  406. function commenttable($rows)
  407. {
  408. global $CURUSER, $HTTP_SERVER_VARS;
  409. begin_main_frame();
  410. begin_frame();
  411. $count = 0;
  412. foreach ($rows as $row)
  413. {
  414. print("<p class=sub>#" . $row["id"] . " by ");
  415. if (isset($row["username"]))
  416. {
  417. $title = $row["title"];
  418. if ($title == "")
  419. $title = get_user_class_name($row["class"]);
  420. else
  421. $title = htmlspecialchars($title);
  422. print("<a name=\"comm". $row["id"] . "\" href=\"userdetails?id=" . $row["user"] . "\"><b>" .
  423. htmlspecialchars($row["username"]) . "</b></a>" . ($row["donor"] == "yes" ? "<img src=\"images/star.gif\" alt=\"Donor\">" : "") . ($row["warned"] == "yes" ? "<img src=".
  424. "\"images/warned.gif\" alt=\"Warned\">" : "") . " ($title)\n");
  425. }
  426. else
  427. print("<a name=\"comm" . $row["id"] . "\"><i>(orphaned)</i></a>\n");
  428. print(" at " . $row["added"] . " GMT" .
  429. ($row["user"] == $CURUSER["id"] || get_user_class() >= UC_MODERATOR ? "- [<a href=\"comment?action=edit&amp;cid=$row[id]\">Edit</a>]" : "") .
  430. (get_user_class() >= UC_MODERATOR ? "- [<a href=\"comment?action=delete&amp;cid=$row[id]\">Delete</a>]" : "") .
  431. ($row["editedby"] && get_user_class() >= UC_MODERATOR ? "- [<a href=\"comment?action=vieworiginal&amp;cid=$row[id]\">View original</a>]" : "") . "</p>\n");
  432. $avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($row["avatar"]) : "");
  433. if (!$avatar)
  434. $avatar = "images/default_avatar.gif";
  435. $text = format_comment($row["text"]);
  436. if ($row["editedby"])
  437. $text .= "<p><font size=\"1\" class=\"small\">Last edited by <a href=\"userdetails?id=$row[editedby]\"><b>$row[username]</b></a> at $row[editedat] GMT</font></p>\n";
  438. begin_table(true);
  439. print("<tr valign=\"top\">\n");
  440. print("<td align=\"center\" width=\"150\" style=\"padding: 0px\"><img width=\"150\" src=\"$avatar\"></td>\n");
  441. print("<td class=\"text\">$text</td>\n");
  442. print("</tr>\n");
  443. end_table();
  444. }
  445. end_frame();
  446. end_main_frame();
  447. }
  448. function searchfield($s) {
  449. return preg_replace(array('/[^a-z0-9]/si', '/^\s*/s', '/\s*$/s', '/\s+/s'), array(" ", "", "", " "), $s);
  450. }
  451. function genrelist() {
  452. $ret = array();
  453. $res = mysql_query("SELECT id, name FROM categories ORDER BY name");
  454. while ($row = mysql_fetch_array($res))
  455. $ret[] = $row;
  456. return $ret;
  457. }
  458. function linkcolor($num) {
  459. if (!$num)
  460. return "red";
  461. // if ($num == 1)
  462. // return "yellow";
  463. return "green";
  464. }
  465. function ratingpic($num) {
  466. global $pic_base_url;
  467. $r = round($num * 2) / 2;
  468. if ($r < 1 || $r > 5)
  469. return;
  470. return "<img src=\"$pic_base_url$r.gif\" border=\"0\" alt=\"rating: $num / 5\" />";
  471. }
  472. function curUserPage($pageTitle) {
  473. global $CURUSER;
  474. mysql_query("UPDATE `users` SET `curPage` = '" . $pageTitle . "' WHERE `id` = " . $CURUSER['id']. "");
  475. }
  476. function torrenttable($res, $variant = "index") {
  477. global $pic_base_url, $CURUSER;
  478. if ($CURUSER["class"] < UC_DONOR)
  479. {
  480. $gigs = $CURUSER["uploaded"] / (1024*1024*1024);
  481. $ratio = (($CURUSER["downloaded"] > 0) ? ($CURUSER["uploaded"] / $CURUSER["downloaded"]) : 0);
  482. if ($ratio < 0.5 || $gigs < 5) $wait = 48;
  483. elseif ($ratio < 0.65 || $gigs < 6.5) $wait = 24;
  484. elseif ($ratio < 0.8 || $gigs < 8) $wait = 12;
  485. elseif ($ratio < 0.95 || $gigs < 9.5) $wait = 6;
  486. else $wait = 0;
  487. }
  488. ?>
  489. <table border="1" cellspacing="0" cellpadding="5">
  490. <tr>
  491. <td class="colhead" align="center">Type</td>
  492. <td class="colhead" align="left">Name</td>
  493. <!--<td class="heading" align="left">DL</td>-->
  494. <?
  495. if ($wait)
  496. {
  497. print("<td class=\"colhead\" align=\"center\">Wait</td>\n");
  498. }
  499. if ($variant == "mytorrents")
  500. {
  501. print("<td class=\"colhead\" align=\"center\">Edit</td>\n");
  502. print("<td class=\"colhead\" align=\"center\">Visible</td>\n");
  503. }
  504. ?>
  505. <td class="colhead" align="right">Files</td>
  506. <td class="colhead" align="right">Comm.</td>
  507. <!--<td class="colhead" align="center">Rating</td>-->
  508. <td class="colhead" align="center">Added</td>
  509. <td class="colhead" align="center">TTL</td>
  510. <td class="colhead" align="center">Size</td>
  511. <!--
  512. <td class="colhead" align="right">Views</td>
  513. <td class="colhead" align="right">Hits</td>
  514. -->
  515. <td class="colhead" align="center">Snatched</td>
  516. <td class="colhead" align=\"right\">Seeders</td>
  517. <td class="colhead" align=\"right\">Leechers</td>
  518. <?
  519. if ($variant == "index")
  520. print("<td class=\"colhead\" align=\"center\">Upped&nbsp;by</td>\n");
  521. print("</tr>\n");
  522. while ($row = mysql_fetch_assoc($res)) {
  523. $id = $row["id"];
  524. print("<tr>\n");
  525. print("<td align=\"center\" style=\"padding: 0px\">");
  526. if (isset($row["cat_name"])) {
  527. print("<a href=\"browse?cat=" . $row["category"] . "\">");
  528. if (isset($row["cat_pic"]) && $row["cat_pic"] != "")
  529. print("<img border=\"0\" src=\"$pic_base_url" . $row["cat_pic"] . "\" alt=\"" . $row["cat_name"] . "\" />");
  530. else
  531. print($row["cat_name"]);
  532. print("</a>");
  533. }
  534. else
  535. print("-");
  536. print("</td>\n");
  537. $dispname = htmlspecialchars($row["name"]);
  538. print("<td align=\"left\"><a href=\"details?");
  539. if ($variant == "mytorrents")
  540. print("returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;");
  541. print("id=$id");
  542. if ($variant == "index")
  543. print("&amp;hit=1");
  544. print("\"><b>$dispname</b></a>\n");
  545. if ($wait)
  546. {
  547. $elapsed = floor((gmtime() - strtotime($row["added"])) / 3600);
  548. if ($elapsed < $wait)
  549. {
  550. $color = dechex(floor(127*($wait - $elapsed)/48 + 128)*65536);
  551. print("<td align=\"center\"><nobr><a href=\"/faq#dl8\"><font color=\"$color\">" . number_format($wait - $elapsed) . " h</font></a></nobr></td>\n");
  552. }
  553. else
  554. print("<td align=\"center\"><nobr>None</nobr></td>\n");
  555. }
  556. if ($variant == "index")
  557. print("<a href=\"download.php/$id/" . rawurlencode($row["filename"]) . "\"><img src=\"images/download.gif\" border=0 alt=Download></a>\n");
  558. else if ($variant == "mytorrents")
  559. print("<td align=\"center\"><a href=\"edit?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;id=" . $row["id"] . "\">edit</a>\n");
  560. print("</td>\n");
  561. if ($variant == "mytorrents") {
  562. print("<td align=\"right\">");
  563. if ($row["visible"] == "no")
  564. print("<b>no</b>");
  565. else
  566. print("yes");
  567. print("</td>\n");
  568. }
  569. if ($row["type"] == "single")
  570. print("<td align=\"right\">" . $row["numfiles"] . "</td>\n");
  571. else {
  572. if ($variant == "index")
  573. print("<td align=\"right\"><b><a href=\"details?id=$id&amp;hit=1&amp;filelist=1\">" . $row["numfiles"] . "</a></b></td>\n");
  574. else
  575. print("<td align=\"right\"><b><a href=\"details?id=$id&amp;filelist=1#filelist\">" . $row["numfiles"] . "</a></b></td>\n");
  576. }
  577. if (!$row["comments"])
  578. print("<td align=\"right\">" . $row["comments"] . "</td>\n");
  579. else {
  580. if ($variant == "index")
  581. print("<td align=\"right\"><b><a href=\"details?id=$id&amp;hit=1&amp;tocomm=1\">" . $row["comments"] . "</a></b></td>\n");
  582. else
  583. print("<td align=\"right\"><b><a href=\"details?id=$id&amp;page=0#startcomments\">" . $row["comments"] . "</a></b></td>\n");
  584. }
  585. /*
  586. print("<td align=\"center\">");
  587. if (!isset($row["rating"]))
  588. print("---");
  589. else {
  590. $rating = round($row["rating"] * 2) / 2;
  591. $rating = ratingpic($row["rating"]);
  592. if (!isset($rating))
  593. print("---");
  594. else
  595. print($rating);
  596. }
  597. print("</td>\n");
  598. */
  599. print("<td align=center><nobr>" . str_replace(" ", "<br />", $row["added"]) . "</nobr></td>\n");
  600. $ttl = (28*24) - floor((gmtime() - sql_timestamp_to_unix_timestamp($row["added"])) / 3600);
  601. if ($ttl == 1) $ttl .= "<br>hour"; else $ttl .= "<br>hours";
  602. print("<td align=center>$ttl</td>\n");
  603. print("<td align=center>" . str_replace(" ", "<br>", mksize($row["size"])) . "</td>\n");
  604. // print("<td align=\"right\">" . $row["views"] . "</td>\n");
  605. // print("<td align=\"right\">" . $row["hits"] . "</td>\n");
  606. $_s = "";
  607. if ($row["times_completed"] != 1)
  608. $_s = "s";
  609. print("<td align=center>" . number_format($row["times_completed"]) . "<br>time$_s</td>\n");
  610. if ($row["seeders"]) {
  611. if ($variant == "index")
  612. {
  613. if ($row["leechers"]) $ratio = $row["seeders"] / $row["leechers"]; else $ratio = 1;
  614. print("<td align=right><b><a href=details?id=$id&amp;hit=1&amp;toseeders=1><font color=" .
  615. get_slr_color($ratio) . ">" . $row["seeders"] . "</font></a></b></td>\n");
  616. }
  617. else
  618. print("<td align=\"right\"><b><a class=\"" . linkcolor($row["seeders"]) . "\" href=\"details?id=$id&amp;dllist=1#seeders\">" .
  619. $row["seeders"] . "</a></b></td>\n");
  620. }
  621. else
  622. print("<td align=\"right\"><span class=\"" . linkcolor($row["seeders"]) . "\">" . $row["seeders"] . "</span></td>\n");
  623. if ($row["leechers"]) {
  624. if ($variant == "index")
  625. print("<td align=right><b><a href=details?id=$id&amp;hit=1&amp;todlers=1>" .
  626. number_format($row["leechers"]) . (isset($peerlink) ? "</a>" : "") .
  627. "</b></td>\n");
  628. else
  629. print("<td align=\"right\"><b><a class=\"" . linkcolor($row["leechers"]) . "\" href=\"details?id=$id&amp;dllist=1#leechers\">" .
  630. $row["leechers"] . "</a></b></td>\n");
  631. }
  632. else
  633. print("<td align=\"right\">0</td>\n");
  634. if ($variant == "index")
  635. print("<td align=center>" . (isset($row["username"]) ? ("<a href=userdetails?id=" . $row["owner"] . "><b>" . htmlspecialchars($row["username"]) . "</b></a>") : "<i>(unknown)</i>") . "</td>\n");
  636. print("</tr>\n");
  637. }
  638. print("</table>\n");
  639. return $rows;
  640. }
  641. function hash_pad($hash) {
  642. return str_pad($hash, 20);
  643. }
  644. function hash_where($name, $hash) {
  645. $shhash = preg_replace('/ *$/s', "", $hash);
  646. return "($name = " . sqlesc($hash) . " OR $name = " . sqlesc($shhash) . ")";
  647. }
  648. function get_user_icons($arr, $big = false)
  649. {
  650. if ($big)
  651. {
  652. $donorpic = "starbig.gif";
  653. $warnedpic = "warnedbig.gif";
  654. $disabledpic = "disabledbig.gif";
  655. $style = "style='margin-left: 4pt'";
  656. }
  657. else
  658. {
  659. $donorpic = "star.gif";
  660. $warnedpic = "warned.gif";
  661. $disabledpic = "disabled.gif";
  662. $style = "style=\"margin-left: 2pt\"";
  663. }
  664. $pics = $arr["donor"] == "yes" ? "<img src=images/$donorpic alt='Donor' border=0 $style>" : "";
  665. if ($arr["enabled"] == "yes")
  666. $pics .= $arr["warned"] == "yes" ? "<img src=images/$warnedpic alt=\"Warned\" border=0 $style>" : "";
  667. else
  668. $pics .= "<img src=images/$disabledpic alt=\"Disabled\" border=0 $style>\n";
  669. return $pics;
  670. }
  671. require "global.php";
  672. function curPageURL() {
  673. $pageURL = 'http';
  674. if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
  675. $pageURL .= "://";
  676. if ($_SERVER["SERVER_PORT"] != "80") {
  677. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  678. } else {
  679. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  680. }
  681. return $pageURL;
  682. }
  683. function logVisits(){
  684. $curPage = curPageURL();
  685. $userIP = $_SERVER['REMOTE_ADDR'];
  686. $agent = $_SERVER['HTTP_USER_AGENT'];
  687. $sqlQuery = "INSERT INTO `x00n`.`viewLog` (
  688. `id` ,
  689. `ip` ,
  690. `agent` ,
  691. `curPage`
  692. )
  693. VALUES (
  694. '', '$userIP', '$agent', '$curPage'
  695. );
  696. ";
  697. @mysql_query($sqlQuery);
  698. }
  699. ?>