PageRenderTime 66ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/sharemarks.php

https://github.com/Bigjoos/U-232-V1
PHP | 228 lines | 186 code | 33 blank | 9 comment | 49 complexity | 7532228650bbba7d2f7796be4a1e3dd5 MD5 | raw file
  1. <?php
  2. /**
  3. * http://btdev.net:1337/svn/test/Installer09_Beta
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 BTDev Installer v.1
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn.
  8. **/
  9. //== Sharemarks.php - by pdq
  10. require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
  11. require_once(INCL_DIR.'user_functions.php');
  12. require_once(INCL_DIR.'torrenttable_functions.php');
  13. require_once(INCL_DIR.'pager_functions.php');
  14. require_once(INCL_DIR.'html_functions.php');
  15. dbconn(false);
  16. loggedinorreturn();
  17. $lang = array_merge( load_language('global'), load_language('torrenttable_functions') );
  18. $htmlout='';
  19. function sharetable($res, $variant = "index") {
  20. global $TBDEV, $CURUSER, $lang;
  21. $htmlout='';
  22. $htmlout.="
  23. <span>Icon Legend :
  24. <img src='{$TBDEV['pic_base_url']}plus.gif' alt='Delete Bookmark' border='none' /> = Delete Bookmark |
  25. <img src='{$TBDEV['pic_base_url']}download.gif' alt='Download Bookmark' border='none' />= Download Torrent |
  26. <img alt='Bookmark is Private' src='{$TBDEV['pic_base_url']}key.gif' border='none' /> = Bookmark is Private |
  27. <img src='{$TBDEV['pic_base_url']}public.gif' alt='Bookmark is Public' border='none' /> = Bookmark is Public</span>
  28. <table border='1' cellspacing='0' cellpadding='5'>
  29. <tr>
  30. <td class='colhead' align='center'>Type</td>
  31. <td class='colhead' align='left'>Name</td>";
  32. $userid = (int)$_GET['id'];
  33. if ($CURUSER['id'] == $userid)
  34. $htmlout.= ($variant == 'index' ? '<td class="colhead" align="center">Download</td><td class="colhead" align="right">' : '').'Delete</td>';
  35. else
  36. $htmlout.= ($variant == 'index' ? '<td class="colhead" align="center">Download</td><td class="colhead" align="right">' : '').'Bookmark</td>';
  37. if ($variant == "mytorrents")
  38. {
  39. $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_edit"]}</td>\n";
  40. $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_visible"]}</td>\n";
  41. }
  42. $htmlout .= "<td class='colhead' align='right'>{$lang["torrenttable_files"]}</td>
  43. <td class='colhead' align='right'>{$lang["torrenttable_comments"]}</td>
  44. <td class='colhead' align='center'>{$lang["torrenttable_added"]}</td>
  45. <td class='colhead' align='center'>{$lang["torrenttable_size"]}</td>
  46. <td class='colhead' align='center'>{$lang["torrenttable_snatched"]}</td>
  47. <td class='colhead' align='right'>{$lang["torrenttable_seeders"]}</td>
  48. <td class='colhead' align='right'>{$lang["torrenttable_leechers"]}</td>";
  49. if ($variant == 'index')
  50. $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_uppedby"]}</td>\n";
  51. $htmlout .= "</tr>\n";
  52. while ($row = mysql_fetch_assoc($res))
  53. {
  54. $id = $row["id"];
  55. $htmlout .= "<tr>\n";
  56. $htmlout .= "<td align='center' style='padding: 0px'>";
  57. if (isset($row["cat_name"]))
  58. {
  59. $htmlout .= "<a href='browse.php?cat={$row['category']}'>";
  60. if (isset($row["cat_pic"]) && $row["cat_pic"] != "")
  61. $htmlout .= "<img border='0' src='{$TBDEV['pic_base_url']}caticons/{$row['cat_pic']}' alt='{$row['cat_name']}' />";
  62. else
  63. {
  64. $htmlout .= $row["cat_name"];
  65. }
  66. $htmlout .= "</a>";
  67. }
  68. else
  69. {
  70. $htmlout .= "-";
  71. }
  72. $htmlout .= "</td>\n";
  73. $dispname = htmlspecialchars($row["name"]);
  74. $htmlout .= "<td align='left'><a href='details.php?";
  75. if ($variant == "mytorrents")
  76. $htmlout .= "returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;";
  77. $htmlout .= "id=$id";
  78. if ($variant == "index")
  79. $htmlout .= "&amp;hit=1";
  80. $htmlout .= "'><b>$dispname</b></a>&nbsp;</td>";
  81. $htmlout.= ($variant == "index" ? "<td align='center'><a href=\"download.php?torrent=".$id."\"><img src='".$TBDEV['pic_base_url']."download.gif' border='0' alt='Download Bookmark!' title='Download Bookmark!' /></a></td>" : "");
  82. $bm = sql_query("SELECT * FROM bookmarks WHERE torrentid=$id && userid=$CURUSER[id]");
  83. $bms = mysql_fetch_assoc($bm);
  84. $bookmarked = (empty($bms)?'<a href=\'bookmark.php?torrent=' . $id . '&amp;action=add\'><img src=\'' . $TBDEV['pic_base_url'] . 'bookmark.gif\' border=\'0\' alt=\'Bookmark it!\' title=\'Bookmark it!\'></a>':'<a href="bookmark.php?torrent=' . $id . '&amp;action=delete"><img src=\'' . $TBDEV['pic_base_url'] . 'plus.gif\' border=\'0\' alt=\'Delete Bookmark!\' title=\'Delete Bookmark!\' /></a>');
  85. $htmlout.= ($variant == "index" ? "<td align='center'>{$bookmarked}</td>" : "");
  86. if ($variant == "mytorrents")
  87. $htmlout .= "</td><td align='center'><a href='edit.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;id={$row['id']}'>".$lang["torrenttable_edit"]."</a>\n";
  88. if ($variant == "mytorrents")
  89. {
  90. $htmlout .= "<td align='right'>";
  91. if ($row["visible"] == "no")
  92. $htmlout .= "<b>".$lang["torrenttable_not_visible"]."</b>";
  93. else
  94. $htmlout .= "".$lang["torrenttable_visible"]."";
  95. $htmlout .= "</td>\n";
  96. }
  97. if ($row["type"] == "single")
  98. {
  99. $htmlout .= "<td align='right'>{$row["numfiles"]}</td>\n";
  100. }
  101. else
  102. {
  103. if ($variant == "index")
  104. {
  105. $htmlout .= "<td align='right'><b><a href='filelist.php?id=$id'>" . $row["numfiles"] . "</a></b></td>\n";
  106. }
  107. else
  108. {
  109. $htmlout .= "<td align='right'><b><a href='filelist.php?id=$id'>" . $row["numfiles"] . "</a></b></td>\n";
  110. }
  111. }
  112. if (!$row["comments"])
  113. {
  114. $htmlout .= "<td align='right'>{$row["comments"]}</td>\n";
  115. }
  116. else
  117. {
  118. if ($variant == "index")
  119. {
  120. $htmlout .= "<td align='right'><b><a href='details.php?id=$id&amp;hit=1&amp;tocomm=1'>" . $row["comments"] . "</a></b></td>\n";
  121. }
  122. else
  123. {
  124. $htmlout .= "<td align='right'><b><a href='details.php?id=$id&amp;page=0#startcomments'>" . $row["comments"] . "</a></b></td>\n";
  125. }
  126. }
  127. $htmlout .= "<td align='center'><span style='white-space: nowrap;'>" . str_replace(",", "<br />", get_date( $row['added'],'')) . "</span></td>\n";
  128. $htmlout .= "
  129. <td align='center'>" . str_replace(" ", "<br />", mksize($row["size"])) . "</td>\n";
  130. if ($row["times_completed"] != 1)
  131. $_s = "".$lang["torrenttable_time_plural"]."";
  132. else
  133. $_s = "".$lang["torrenttable_time_singular"]."";
  134. $htmlout .= "<td align='center'><a href='snatches.php?id=$id'>" . number_format($row["times_completed"]) . "<br />$_s</a></td>\n";
  135. if ($row["seeders"])
  136. {
  137. if ($variant == "index")
  138. {
  139. if ($row["leechers"]) $ratio = $row["seeders"] / $row["leechers"]; else $ratio = 1;
  140. $htmlout .= "<td align='right'><b><a href='peerlist.php?id=$id#seeders'>
  141. <font color='" .get_slr_color($ratio) . "'>{$row["seeders"]}</font></a></b></td>\n";
  142. }
  143. else
  144. {
  145. $htmlout .= "<td align='right'><b><a class='" . linkcolor($row["seeders"]) . "' href='peerlist.php?id=$id#seeders'>{$row["seeders"]}</a></b></td>\n";
  146. }
  147. }
  148. else
  149. {
  150. $htmlout .= "<td align='right'><span class='" . linkcolor($row["seeders"]) . "'>" . $row["seeders"] . "</span></td>\n";
  151. }
  152. if ($row["leechers"])
  153. {
  154. if ($variant == "index")
  155. $htmlout .= "<td align='right'><b><a href='peerlist.php?id=$id#leechers'>" .
  156. number_format($row["leechers"]) . "</a></b></td>\n";
  157. else
  158. $htmlout .= "<td align='right'><b><a class='" . linkcolor($row["leechers"]) . "' href='peerlist.php?id=$id#leechers'>{$row["leechers"]}</a></b></td>\n";
  159. }
  160. else
  161. $htmlout .= "<td align='right'>0</td>\n";
  162. if ($variant == "index")
  163. $htmlout .= "<td align='center'>" . (isset($row["username"]) ? ("<a href='userdetails.php?id=" . $row["owner"] . "'><b>" . htmlspecialchars($row["username"]) . "</b></a>") : "<i>(".$lang["torrenttable_unknown_uploader"].")</i>") . "</td>\n";
  164. $htmlout .= "</tr>\n";
  165. }
  166. $htmlout .= "</table>\n";
  167. return $htmlout;
  168. }
  169. //==Sharemarks
  170. $userid = isset($_GET['id']) ? (int)$_GET['id'] : '';
  171. if (!is_valid_id($userid))
  172. stderr("Error", "Invalid ID.");
  173. $res = sql_query("SELECT id, username FROM users WHERE id = $userid") or sqlerr();
  174. $arr = mysql_fetch_array($res);
  175. $htmlout.="<h1>Sharemarks for <a href=\"userdetails.php?id=".$userid."\">".$arr['username']."</a></h1>";
  176. $htmlout.="<b><a href=\"bookmarks.php\">My Bookmarks</a></b>";
  177. $res = sql_query("SELECT COUNT(id) FROM bookmarks WHERE userid = $userid");
  178. $row = mysql_fetch_array($res);
  179. $count = $row[0];
  180. $torrentsperpage = $CURUSER["torrentsperpage"];
  181. if (!$torrentsperpage)
  182. $torrentsperpage = 25;
  183. if ($count) {
  184. $pager = pager($torrentsperpage, $count, "sharemarks.php?&amp;");
  185. $query1 = "SELECT bookmarks.id as bookmarkid, users.username, users.id as owner, torrents.id, torrents.name, torrents.type, torrents.comments, torrents.leechers, torrents.seeders, 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']}" or sqlerr(__FILE__, __LINE__);
  186. $res = sql_query($query1) or sqlerr();
  187. }
  188. if ($count) {
  189. $htmlout .= $pager['pagertop'];
  190. $htmlout .= sharetable($res, "index", TRUE);
  191. $htmlout .= $pager['pagerbottom'];
  192. }
  193. print stdhead("Sharemarks for " . $arr['username']) . $htmlout . stdfoot();
  194. ?>