PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/TBDev/installer_v4_1/bookmarks.php

https://github.com/cybernet/CyBerFuN-CoDeX
PHP | 259 lines | 192 code | 33 blank | 34 comment | 68 complexity | 5f70072f9ea0f951052d5656f049bc4d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // bookmarks.php - by pdq
  3. require_once("include/bittorrent.php");
  4. require_once ("include/bbcode_functions.php");
  5. dbconn(false);
  6. maxcoder();
  7. if (!logged_in()) {
  8. header("HTTP/1.0 404 Not Found");
  9. // moddifed logginorreturn by retro//Remember to change the following line to match your server
  10. 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 ".$SITENAME." Server at " . $_SERVER['SERVER_NAME'] . " Port 80</address></body></html>\n");
  11. die();
  12. }
  13. function bookmarktable($res, $variant = "index")
  14. {
  15. global $pic_base_url, $CURUSER;
  16. $wait = 0;
  17. if ($CURUSER["class"] < UC_VIP) {
  18. $gigs = $CURUSER["uploaded"] / (1024 * 1024 * 1024);
  19. $ratio = (($CURUSER["downloaded"] > 0) ? ($CURUSER["uploaded"] / $CURUSER["downloaded"]) : 0);
  20. if ($ratio < 0.5 || $gigs < 5) $wait = 48;
  21. elseif ($ratio < 0.65 || $gigs < 6.5) $wait = 24;
  22. elseif ($ratio < 0.8 || $gigs < 8) $wait = 12;
  23. elseif ($ratio < 0.95 || $gigs < 9.5) $wait = 6;
  24. else $wait = 0;
  25. }
  26. ?>
  27. <p align="center">Icon Legend :
  28. <img alt="Delete Bookmark" src="pic/plus2.gif" border="none">
  29. = Delete Bookmark |
  30. <img alt="Download Bookmark" by="" src="pic/download.gif">
  31. = Download Torrent |
  32. <img alt="Bookmark is Private" src="pic/key.gif" border="none">
  33. = Bookmark is Private |
  34. <img alt="Bookmark is Public" src="pic/public.gif" border="none">
  35. = Bookmark is Public</p>
  36. <table border="1" cellspacing=0 cellpadding=5>
  37. <tr>
  38. <td class="colhead" align="center">Type</td>
  39. <td class="colhead" align=left>Name</td>
  40. <?php
  41. echo ($variant == 'index' ? '<td class=colhead align=center>Delete</td><td class=colhead align="right">' : '') . 'Download</td><td class=colhead align="right">Share</td>';
  42. if ($wait) {
  43. print("<td class=\"colhead\" align=\"center\">Wait</td>\n");
  44. }
  45. if ($variant == "mytorrents") {
  46. print("<td class=\"colhead\" align=\"center\">Edit</td>\n");
  47. print("<td class=\"colhead\" align=\"center\">Visible</td>\n");
  48. }
  49. ?>
  50. <td class="colhead" align=right>Files</td>
  51. <td class="colhead" align=right>Comm.</td>
  52. <!--<td class="colhead" align="center">Rating</td>-->
  53. <td class="colhead" align="center">Added</td>
  54. <td class="colhead" align="center">TTL</td>
  55. <td class="colhead" align="center">Size</td>
  56. <!--
  57. <td class="colhead" align=right>Views</td>
  58. <td class="colhead" align=right>Hits</td>
  59. -->
  60. <td class="colhead" align="center">Snatched</td>
  61. <td class="colhead" align=right>Seeders</td>
  62. <td class="colhead" align=right>Leechers</td>
  63. <?php
  64. if ($variant == "index")
  65. print("<td class=\"colhead\" align=center>Upped&nbsp;by</td>\n");
  66. print("</tr>\n");
  67. while ($row = mysql_fetch_assoc($res)) {
  68. $id = $row["id"];
  69. print("<tr>\n");
  70. print("<td align=center style='padding: 0px'>");
  71. if (isset($row["cat_name"])) {
  72. print("<a href=\"browse.php?cat=" . $row["category"] . "\">");
  73. if (isset($row["cat_pic"]) && $row["cat_pic"] != "")
  74. print("<img border=\"0\" src=\"{$pic_base_url}/{$row['cat_pic']}\" alt=\"{$row['cat_name']}\" />");
  75. else
  76. print($row["cat_name"]);
  77. print("</a>");
  78. } else
  79. print("-");
  80. print("</td>\n");
  81. $dispname = htmlspecialchars($row["name"]);
  82. print("<td align=left><a href=\"details.php?");
  83. if ($variant == "mytorrents")
  84. print("returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;");
  85. print("id=$id");
  86. if ($variant == "index")
  87. print("&amp;hit=1");
  88. print("\"><b>$dispname</b></a>\n");
  89. echo ($variant == 'index' ? '<td align=center><a href="bookmark.php?torrent=' . $id . '&action=delete"><img src="' . $pic_base_url . 'plus2.gif" border="0" alt="Delete Bookmark!" title="Delete Bookmark!"></a></td>' : '');
  90. echo ($variant == 'index' ? '<td align=center><a href=download.php/' . $id . '/' . rawurlencode($row['filename']) . '><img src="' . $pic_base_url . 'download.gif" border="0" alt="Download Bookmark!" title="Download Bookmark!"></a></td>' : '');
  91. $bm = mysql_query("SELECT * FROM bookmarks WHERE torrentid=$id && userid=$CURUSER[id]");
  92. $bms = mysql_fetch_assoc($bm);
  93. if ($bms['private'] == 'yes' && $bms['userid'] == $CURUSER['id']) {
  94. $makepriv = '<a href="bookmark.php?torrent=' . $id . '&action=public"><img src="' . $pic_base_url . 'key.gif" border="0" alt="Mark Bookmark Public!" title="Mark Bookmark Public!"></a>';
  95. echo ($variant == 'index' ? '<td align=center>' . $makepriv . '</td>' : '');
  96. } elseif ($bms['private'] == 'no' && $bms['userid'] == $CURUSER['id']) {
  97. $makepriv = '<a href="bookmark.php?torrent=' . $id . '&action=private"><img src="' . $pic_base_url . 'public.gif" border="0" alt="Mark Bookmark Private!" title="Mark Bookmark Private!"></a>';
  98. echo ($variant == 'index' ? '<td align=center>' . $makepriv . '</td>' : '');
  99. }
  100. if ($wait) {
  101. $elapsed = floor((gmtime() - strtotime($row["added"])) / 3600);
  102. if ($elapsed < $wait) {
  103. $color = dechex(floor(127 * ($wait - $elapsed) / 48 + 128) * 65536);
  104. print("<td align=center><nobr><a href=\"faq.php#dl8\"><font color=\"$color\">" . number_format($wait - $elapsed) . " h</font></a></nobr></td>\n");
  105. } else
  106. print("<td align=center><nobr>None</nobr></td>\n");
  107. }
  108. /*
  109. if ($row["nfoav"] && get_user_class() >= UC_POWER_USER)
  110. print("<a href=viewnfo.php?id=$row[id]><img src=\"{$pic_base_url}viewnfo.gif" border=0 alt='View NFO'></a>\n");
  111. else */if ($variant == "mytorrents")
  112. print("<td align=\"center\"><a href=\"edit.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;id=" . $row["id"] . "\">edit</a>\n");
  113. print("</td>\n");
  114. if ($variant == "mytorrents") {
  115. print("<td align=\"right\">");
  116. if ($row["visible"] == "no")
  117. print("<b>no</b>");
  118. else
  119. print("yes");
  120. print("</td>\n");
  121. }
  122. if ($row["type"] == "single")
  123. print("<td align=\"right\">" . $row["numfiles"] . "</td>\n");
  124. else {
  125. if ($variant == "index")
  126. print("<td align=\"right\"><b><a href=\"filelist.php?id=$id\">" . $row["numfiles"] . "</a></b></td>\n");
  127. else
  128. print("<td align=\"right\"><b><a href=\"filelist.php?id=$id\">" . $row["numfiles"] . "</a></b></td>\n");
  129. }
  130. if (!$row["comments"])
  131. print("<td align=\"right\">" . $row["comments"] . "</td>\n");
  132. else {
  133. if ($variant == "index")
  134. print("<td align=\"right\"><b><a href=\"details.php?id=$id&amp;hit=1&amp;tocomm=1\">" . $row["comments"] . "</a></b></td>\n");
  135. else
  136. print("<td align=\"right\"><b><a href=\"details.php?id=$id&amp;page=0#startcomments\">" . $row["comments"] . "</a></b></td>\n");
  137. }
  138. /*
  139. print("<td align=\"center\">");
  140. if (!isset($row["rating"]))
  141. print("---");
  142. else {
  143. $rating = round($row["rating"] * 2) / 2;
  144. $rating = ratingpic($row["rating"]);
  145. if (!isset($rating))
  146. print("---");
  147. else
  148. print($rating);
  149. }
  150. print("</td>\n");
  151. */
  152. print("<td align=center><nobr>" . str_replace(" ", "<br />", $row["added"]) . "</nobr></td>\n");
  153. $ttl = (28 * 24) - floor((gmtime() - sql_timestamp_to_unix_timestamp($row["added"])) / 3600);
  154. if ($ttl == 1) $ttl .= "<br />hour";
  155. else $ttl .= "<br />hours";
  156. print("<td align=center>$ttl</td>\n");
  157. print("<td align=center>" . str_replace(" ", "<br />", prefixed($row["size"])) . "</td>\n");
  158. // print("<td align=\"right\">" . $row["views"] . "</td>\n");
  159. // print("<td align=\"right\">" . $row["hits"] . "</td>\n");
  160. $_s = "";
  161. if ($row["times_completed"] != 1)
  162. $_s = "s";
  163. print("<td align=center>" . number_format($row["times_completed"]) . "<br />time$_s</td>\n");
  164. if ($row["seeders"]) {
  165. if ($variant == "index") {
  166. if ($row["leechers"]) $ratio = $row["seeders"] / $row["leechers"];
  167. else $ratio = 1;
  168. print("<td align=right><b><a href=peerlist.php?id=$id#seeders><font color=" .
  169. get_slr_color($ratio) . ">" . $row["seeders"] . "</font></a></b></td>\n");
  170. } else
  171. print("<td align=\"right\"><b><a class=\"" . linkcolor($row["seeders"]) . "\" href=\"peerlist.php?id=$id#seeders\">" . $row["seeders"] . "</a></b></td>\n");
  172. } else
  173. print("<td align=\"right\"><span class=\"" . linkcolor($row["seeders"]) . "\">" . $row["seeders"] . "</span></td>\n");
  174. if ($row["leechers"]) {
  175. if ($variant == "index")
  176. print("<td align=right><b><a href=peerlist.php?id=$id#leechers>" .
  177. number_format($row["leechers"]) . "</a></b></td>\n");
  178. else
  179. print("<td align=\"right\"><b><a class=\"" . linkcolor($row["leechers"]) . "\" href=\"peerlist.php?id=$id#leechers\">" . $row["leechers"] . "</a></b></td>\n");
  180. } else
  181. print("<td align=\"right\">0</td>\n");
  182. if ($variant == "index")
  183. print("<td align=center>" . (isset($row["username"]) ? ("<a href=userdetails.php?id=" . $row["owner"] . "><b>" . htmlspecialchars($row["username"]) . "</b></a>") : "<i>(unknown)</i>") . "</td>\n");
  184. print("</tr>\n");
  185. }
  186. print("</table>\n");
  187. // return $rows;
  188. }
  189. // GO!
  190. $userid = isset($_GET['id']) ? (int)$_GET['id'] : $CURUSER['id'];
  191. if (!is_valid_id($userid))
  192. stderr("Error", "Invalid ID.");
  193. if ($userid != $CURUSER["id"])
  194. stderr("Error", "Access denied. Try <a href=\"sharemarks.php?id=" . $userid . "\">Here</a>");
  195. $res = mysql_query("SELECT id, username FROM users WHERE id = $userid") or sqlerr();
  196. $arr = mysql_fetch_array($res);
  197. stdhead("My Bookmarks");
  198. echo '<h1>My Bookmarks</h2>';
  199. $res = mysql_query("SELECT COUNT(id) FROM bookmarks WHERE userid = $userid");
  200. $row = mysql_fetch_array($res);
  201. $count = $row[0];
  202. $torrentsperpage = $CURUSER["torrentsperpage"];
  203. if (!$torrentsperpage)
  204. $torrentsperpage = 25;
  205. if ($count) {
  206. // $pager = pager($torrentsperpage, $count, "bookmarks.php?");//TB
  207. list($pagertop, $pagerbottom, $limit) = pager(25, $count, "bookmarks.php?");
  208. /*//TB
  209. $query = "SELECT bookmarks.id as bookmarkid, users.username,users.id as owner, torrents.id, torrents.name, torrents.type, torrents.comments, torrents.leechers, torrents.seeders, ROUND(torrents.ratingsum / torrents.numratings) AS rating, categories.name AS cat_name, categories.image AS cat_pic, torrents.save_as, torrents.numfiles, torrents.added, torrents.filename, torrents.size, torrents.views, torrents.visible, torrents.hits, torrents.times_completed, torrents.category FROM bookmarks LEFT JOIN torrents ON bookmarks.torrentid = torrents.id LEFT JOIN users on torrents.owner = users.id LEFT JOIN categories ON torrents.category = categories.id WHERE bookmarks.userid = $userid AND bookmarks.private = 'no' ORDER BY torrents.id DESC {$pager['limit']}";
  210. $res = mysql_query($query) or sqlerr();
  211. */
  212. $res = mysql_query("SELECT bookmarks.id as bookmarkid, users.username,users.id as owner, torrents.id, torrents.name, torrents.type, torrents.comments, torrents.leechers, torrents.seeders, ROUND(torrents.ratingsum / torrents.numratings) AS rating, categories.name AS cat_name, categories.image AS cat_pic, torrents.save_as, torrents.numfiles, torrents.added, torrents.filename, torrents.size, torrents.views, torrents.visible, torrents.hits, torrents.times_completed, torrents.category FROM bookmarks LEFT JOIN torrents ON bookmarks.torrentid = torrents.id LEFT JOIN users on torrents.owner = users.id LEFT JOIN categories ON torrents.category = categories.id WHERE bookmarks.userid = $userid ORDER BY torrents.id DESC $limit") or sqlerr();
  213. }
  214. if ($count) {
  215. print($pagertop);
  216. bookmarktable($res, "index", true);
  217. print($pagerbottom);
  218. /*//TB
  219. print($pager['pagertop']);
  220. sharetable($res, "index", TRUE);
  221. print($pager['pagerbottom']);
  222. */
  223. }
  224. stdfoot();
  225. ?>