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.

votes.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?
  2. // We need these to do our rankification
  3. include(SERVER_ROOT.'/sections/torrents/ranking_funcs.php');
  4. $UserVotes = Votes::get_user_votes($LoggedUser['ID']);
  5. if (!empty($_GET['advanced']) && check_perms('site_advanced_top10')) {
  6. $Details = 'all';
  7. $Limit = 25;
  8. if (!empty($_GET['tags'])) {
  9. $TagsAny = isset($_GET['anyall']) && $_GET['anyall'] === 'any';
  10. $Tags = explode(',', str_replace('.', '_', trim($_GET['tags'])));
  11. foreach ($Tags as $Tag) {
  12. $Tag = preg_replace('/[^a-z0-9_]/', '', $Tag);
  13. if ($Tag != '') {
  14. $TagWhere[] = "g.TagList REGEXP '[[:<:]]".db_string($Tag)."[[:>:]]'";
  15. }
  16. }
  17. $Operator = $TagsAny ? ' OR ' : ' AND ';
  18. $Where[] = '('.implode($Operator, $TagWhere).')';
  19. }
  20. $Year1 = (int)$_GET['year1'];
  21. $Year2 = (int)$_GET['year2'];
  22. if ($Year1 > 0 && $Year2 <= 0) {
  23. $Where[] = "g.Year = $Year1";
  24. } elseif ($Year1 > 0 && $Year2 > 0) {
  25. $Where[] = "g.Year BETWEEN $Year1 AND $Year2";
  26. } elseif ($Year2 > 0 && $Year1 <= 0) {
  27. $Where[] = "g.Year <= $Year2";
  28. }
  29. } else {
  30. $Details = 'all';
  31. // defaults to 10 (duh)
  32. $Limit = isset($_GET['limit']) ? intval($_GET['limit']) : 25;
  33. $Limit = in_array($Limit, array(25, 100, 250)) ? $Limit : 25;
  34. }
  35. $Filtered = !empty($Where);
  36. if (!empty($Where)) {
  37. $Where = implode(' AND ', $Where);
  38. }
  39. $WhereSum = (empty($Where)) ? '' : md5($Where);
  40. // Unlike the other top 10s, this query just gets some raw stats
  41. // We'll need to do some fancy-pants stuff to translate it into
  42. // BPCI scores before getting the torrent data
  43. $Query = '
  44. SELECT v.GroupID, v.Ups, v.Total, v.Score
  45. FROM torrents_votes AS v';
  46. if (!empty($Where)) {
  47. $Query .= "
  48. JOIN torrents_group AS g ON g.ID = v.GroupID
  49. WHERE $Where AND ";
  50. } else {
  51. $Query .= '
  52. WHERE ';
  53. }
  54. $Query .= "
  55. Score > 0
  56. ORDER BY Score DESC
  57. LIMIT $Limit";
  58. $TopVotes = $Cache->get_value('top10votes_'.$Limit.$WhereSum);
  59. if ($TopVotes === false) {
  60. if ($Cache->get_query_lock('top10votes')) {
  61. $DB->query($Query);
  62. $Results = $DB->to_array('GroupID', MYSQLI_ASSOC, false);
  63. $Ranks = Votes::calc_ranks($DB->to_pair('GroupID', 'Score', false));
  64. $Groups = Torrents::get_groups(array_keys($Results));
  65. $TopVotes = array();
  66. foreach ($Results as $GroupID => $Votes) {
  67. $TopVotes[$GroupID] = $Groups[$GroupID];
  68. $TopVotes[$GroupID]['Ups'] = $Votes['Ups'];
  69. $TopVotes[$GroupID]['Total'] = $Votes['Total'];
  70. $TopVotes[$GroupID]['Score'] = $Votes['Score'];
  71. $TopVotes[$GroupID]['Rank'] = $Ranks[$GroupID];
  72. }
  73. $Cache->cache_value('top10votes_'.$Limit.$WhereSum, $TopVotes, 60 * 30);
  74. $Cache->clear_query_lock('top10votes');
  75. } else {
  76. $TopVotes = false;
  77. }
  78. }
  79. View::show_header("Top $Limit Voted Groups",'browse,voting');
  80. ?>
  81. <div class="thin">
  82. <div class="header">
  83. <h2>Top <?=$Limit?> Voted Groups</h2>
  84. <? Top10View::render_linkbox("votes"); ?>
  85. </div>
  86. <?
  87. if (check_perms('site_advanced_top10')) { ?>
  88. <form class="search_form" name="votes" action="" method="get">
  89. <input type="hidden" name="advanced" value="1" />
  90. <input type="hidden" name="type" value="votes" />
  91. <table cellpadding="6" cellspacing="1" border="0" class="layout border" width="100%">
  92. <tr id="tagfilter">
  93. <td class="label">Tags (comma-separated):</td>
  94. <td class="ft_taglist">
  95. <input type="text" name="tags" size="75" value="<? if (!empty($_GET['tags'])) { echo display_str($_GET['tags']);} ?>" />&nbsp;
  96. <input type="radio" id="rdoAll" name="anyall" value="all"<?=(!isset($TagsAny) ? ' checked="checked"' : '')?> /><label for="rdoAll"> All</label>&nbsp;&nbsp;
  97. <input type="radio" id="rdoAny" name="anyall" value="any"<?=(isset($TagsAny) ? ' checked="checked"' : '')?> /><label for="rdoAny"> Any</label>
  98. </td>
  99. </tr>
  100. <tr id="yearfilter">
  101. <td class="label">Year:</td>
  102. <td class="ft_year">
  103. <input type="text" name="year1" size="4" value="<? if (!empty($_GET['year1'])) { echo display_str($_GET['year1']);} ?>" />
  104. to
  105. <input type="text" name="year2" size="4" value="<? if (!empty($_GET['year2'])) { echo display_str($_GET['year2']);} ?>" />
  106. </td>
  107. </tr>
  108. <tr>
  109. <td colspan="2" class="center">
  110. <input type="submit" value="Filter torrents" />
  111. </td>
  112. </tr>
  113. </table>
  114. </form>
  115. <?
  116. }
  117. $Bookmarks = Bookmarks::all_bookmarks('torrent');
  118. ?>
  119. <h3>Top <?=$Limit?>
  120. <?
  121. if (empty($_GET['advanced'])) { ?>
  122. <small class="top10_quantity_links">
  123. <?
  124. switch ($Limit) {
  125. case 100: ?>
  126. - <a href="top10.php?type=votes" class="brackets">Top 25</a>
  127. - <span class="brackets">Top 100</span>
  128. - <a href="top10.php?type=votes&amp;limit=250" class="brackets">Top 250</a>
  129. <? break;
  130. case 250: ?>
  131. - <a href="top10.php?type=votes" class="brackets">Top 25</a>
  132. - <a href="top10.php?type=votes&amp;limit=100" class="brackets">Top 100</a>
  133. - <span class="brackets">Top 250</span>
  134. <? break;
  135. default: ?>
  136. - <span class="brackets">Top 25</span>
  137. - <a href="top10.php?type=votes&amp;limit=100" class="brackets">Top 100</a>
  138. - <a href="top10.php?type=votes&amp;limit=250" class="brackets">Top 250</a>
  139. <? } ?>
  140. </small>
  141. <?
  142. } ?>
  143. </h3>
  144. <?
  145. $TorrentTable = '';
  146. foreach ($TopVotes as $GroupID => $Group) {
  147. extract(Torrents::array_group($Group));
  148. $UpVotes = $Group['Ups'];
  149. $TotalVotes = $Group['Total'];
  150. $Score = $Group['Score'];
  151. $DownVotes = $TotalVotes - $UpVotes;
  152. $IsBookmarked = in_array($GroupID, $Bookmarks);
  153. $UserVote = isset($UserVotes[$GroupID]) ? $UserVotes[$GroupID]['Type'] : '';
  154. $TorrentTags = new Tags($TagList);
  155. $DisplayName = "$Group[Rank] - ";
  156. $DisplayName .= Artists::display_artists($Artists);
  157. $DisplayName .= '<a href="torrents.php?id='.$GroupID.'" dir="ltr"';
  158. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  159. $DisplayName .= ' onmouseover="getCover(event)" cover="'.ImageTools::process($WikiImage, true).'" onmouseleave="ungetCover(event)"';
  160. }
  161. $DisplayName .= '>'.$GroupName.'</a>';
  162. if ($GroupYear > 0) {
  163. $DisplayName = $DisplayName. " [$GroupYear]";
  164. }
  165. // Start an output buffer, so we can store this output in $TorrentTable
  166. ob_start();
  167. if (count($Torrents) > 1 || $GroupCategoryID == 1) {
  168. // Grouped torrents
  169. $GroupSnatched = false;
  170. foreach ($Torrents as &$Torrent) {
  171. if (($Torrent['IsSnatched'] = Torrents::has_snatched($Torrent['ID'])) && !$GroupSnatched) {
  172. $GroupSnatched = true;
  173. }
  174. }
  175. unset($Torrent);
  176. $SnatchedGroupClass = $GroupSnatched ? ' snatched_group' : '';
  177. ?>
  178. <tr class="group<?=$SnatchedGroupClass?>" id="group_<?=$GroupID?>">
  179. <td class="center">
  180. <div id="showimg_<?=$GroupID?>" class="show_torrents">
  181. <a class="tooltip show_torrents_link" onclick="toggle_group(<?=$GroupID?>, this, event);" title="Toggle this group (Hold &quot;Shift&quot; to toggle all groups)"></a>
  182. </div>
  183. </td>
  184. <td class="center cats_col">
  185. <div title="<?=Format::pretty_category($GroupCategoryID)?>" class="tooltip <?=Format::css_category($GroupCategoryID)?>"></div>
  186. </td>
  187. <td class="big_info">
  188. <div class="group_info clear">
  189. <strong><?=$DisplayName?></strong> <!--<?Votes::vote_link($GroupID, $UserVote);?>-->
  190. <? if ($IsBookmarked) { ?>
  191. <span class="remove_bookmark float_right">
  192. <a href="#" class="bookmarklink_torrent_<?=$GroupID?> brackets" onclick="Unbookmark('torrent', <?=$GroupID?>, 'Bookmark'); return false;">Remove bookmark</a>
  193. </span>
  194. <? } else { ?>
  195. <span class="add_bookmark float_right">
  196. <a href="#" class="bookmarklink_torrent_<?=$GroupID?> brackets" onclick="Bookmark('torrent', <?=$GroupID?>, 'Remove bookmark'); return false;">Bookmark</a>
  197. </span>
  198. <? } ?>
  199. <div class="tags"><?=$TorrentTags->format()?></div>
  200. </div>
  201. </td>
  202. <td colspan="4" class="votes_info_td">
  203. <span style="white-space: nowrap;">
  204. <span class="favoritecount_small tooltip" title="<?=$UpVotes . ($UpVotes == 1 ? ' upvote' : ' upvotes')?>"><span id="upvotes"><?=number_format($UpVotes)?></span> <span class="vote_album_up">&and;</span></span>
  205. &nbsp; &nbsp;
  206. <span class="favoritecount_small tooltip" title="<?=$DownVotes . ($DownVotes == 1 ? ' downvote' : ' downvotes')?>"><span id="downvotes"><?=number_format($DownVotes)?></span> <span class="vote_album_down">&or;</span></span>
  207. &nbsp;
  208. <span style="float: right;"><span class="favoritecount_small" id="totalvotes"><?=number_format($TotalVotes)?></span> Total</span>
  209. </span>
  210. <br />
  211. <span style="white-space: nowrap;">
  212. <span class="tooltip_interactive" title="&lt;span style=&quot;font-weight: bold;&quot;&gt;Score: <?=number_format($Score * 100, 4)?>&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the lower bound of the binomial confidence interval &lt;a href=&quot;wiki.php?action=article&amp;id=1037&quot;&gt;described here&lt;/a&gt;, multiplied by 100." data-title-plain="Score: <?=number_format($Score * 100, 4)?>. This is the lower bound of the binomial confidence interval described in the Favorite Album Votes wiki article, multiplied by 100.">Score: <span class="favoritecount_small"><?=number_format($Score * 100, 1)?></span></span>
  213. &nbsp; | &nbsp;
  214. <span class="favoritecount_small"><?=number_format($UpVotes / $TotalVotes * 100, 1)?>%</span> positive
  215. </span>
  216. </td>
  217. </tr>
  218. <?
  219. foreach ($Torrents as $TorrentID => $Torrent) {
  220. //Get report info, use the cache if available, if not, add to it.
  221. $Reported = false;
  222. $Reports = Torrents::get_reports($TorrentID);
  223. if (count($Reports) > 0) {
  224. $Reported = true;
  225. }
  226. $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : '';
  227. ?>
  228. <tr class="group_torrent torrent_row groupid_<?=$GroupID?> <?=$SnatchedTorrentClass . $SnatchedGroupClass?> hidden">
  229. <td colspan="3">
  230. <span>
  231. [ <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>" class="tooltip" title="Download">DL</a>
  232. <? if (Torrents::can_use_token($Torrent)) { ?>
  233. | <a href="torrents.php?action=download&amp;id=<?=$TorrentID ?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
  234. <? } ?>
  235. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]
  236. </span>
  237. &nbsp;&nbsp;&raquo;&nbsp; <a href="torrents.php?id=<?=$GroupID?>&amp;torrentid=<?=$TorrentID?>"><?=Torrents::torrent_info($Torrent)?><? if ($Reported) { ?> / <strong class="torrent_label tl_reported">Reported</strong><? } ?></a>
  238. </td>
  239. <td class="number_column nobr"><?=Format::get_size($Torrent['Size'])?></td>
  240. <td class="number_column"><?=number_format($Torrent['Snatched'])?></td>
  241. <td class="number_column<?=($Torrent['Seeders'] == 0) ? ' r00' : '' ?>"><?=number_format($Torrent['Seeders'])?></td>
  242. <td class="number_column"><?=number_format($Torrent['Leechers'])?></td>
  243. </tr>
  244. <?
  245. }
  246. } else { //if (count($Torrents) > 1 || $GroupCategoryID == 1)
  247. // Viewing a type that does not require grouping
  248. list($TorrentID, $Torrent) = each($Torrents);
  249. $Torrent['IsSnatched'] = Torrents::has_snatched($TorrentID);
  250. $DisplayName = $Group['Rank'] .' - <a href="torrents.php?id='.$GroupID.'" dir="ltr"';
  251. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  252. $DisplayName .= ' onmouseover="getCover(event)" cover="'.ImageTools::process($WikiImage, true).'" onmouseleave="ungetCover(event)"';
  253. }
  254. $DisplayName .= '>'.$GroupName.'</a>';
  255. if ($Torrent['IsSnatched']) {
  256. $DisplayName .= ' ' . Format::torrent_label('Snatched!');
  257. }
  258. if ($Torrent['FreeTorrent'] == '1') {
  259. $DisplayName .= ' ' . Format::torrent_label('Freeleech!');
  260. } elseif ($Torrent['FreeTorrent'] == '2') {
  261. $DisplayName .= ' ' . Format::torrent_label('Neutral leech!');
  262. } elseif (Torrents::has_token($TorrentID)) {
  263. $DisplayName .= ' ' . Format::torrent_label('Personal freeleech!');
  264. }
  265. $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : '';
  266. ?>
  267. <tr class="torrent torrent_row<?=$SnatchedTorrentClass . $SnatchedGroupClass?>" id="group_<?=$GroupID?>">
  268. <td></td>
  269. <td class="center cats_col">
  270. <div title="<?=Format::pretty_category($GroupCategoryID)?>" class="tooltip <?=Format::css_category($GroupCategoryID)?>">
  271. </div>
  272. </td>
  273. <td class="big_info">
  274. <div class="group_info clear">
  275. <span>
  276. [ <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>" class="tooltip" title="Download">DL</a>
  277. <? if (Torrents::can_use_token($Torrent)) { ?>
  278. | <a href="torrents.php?action=download&amp;id=<?=$TorrentID ?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
  279. <? } ?>
  280. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a>
  281. <? if ($IsBookmarked) { ?>
  282. | <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="remove_bookmark" onclick="Unbookmark('torrent', <?=$GroupID?>, 'Bookmark'); return false;">Remove bookmark</a>
  283. <? } else { ?>
  284. | <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="add_bookmark" onclick="Bookmark('torrent', <?=$GroupID?>, 'Remove bookmark'); return false;">Bookmark</a>
  285. <? } ?>
  286. ]
  287. </span>
  288. <strong><?=$DisplayName?></strong> <!--<?Votes::vote_link($GroupID, $UserVote);?>-->
  289. <div class="tags"><?=$TorrentTags->format()?></div>
  290. </div>
  291. </td>
  292. <td class="number_column nobr"><?=Format::get_size($Torrent['Size'])?></td>
  293. <td class="number_column"><?=number_format($Torrent['Snatched'])?></td>
  294. <td class="number_column<?=($Torrent['Seeders'] == 0) ? ' r00' : '' ?>"><?=number_format($Torrent['Seeders'])?></td>
  295. <td class="number_column"><?=number_format($Torrent['Leechers'])?></td>
  296. </tr>
  297. <?
  298. } //if (count($Torrents) > 1 || $GroupCategoryID == 1)
  299. $TorrentTable .= ob_get_clean();
  300. }
  301. ?>
  302. <table class="torrent_table grouping cats box" id="discog_table">
  303. <tr class="colhead_dark">
  304. <td><!-- expand/collapse --></td>
  305. <td class="cats_col"><!-- category --></td>
  306. <td width="70%">Torrents</td>
  307. <td>Size</td>
  308. <td class="sign snatches"><img src="static/styles/<?=$LoggedUser['StyleName'] ?>/images/snatched.png" alt="Snatches" title="Snatches" class="tooltip" /></td>
  309. <td class="sign seeders"><svg width="11" height="15" fill="white" class="tooltip" alt="Seeders" title="Seeders"><polygon points="0,7 5.5,0 11,7 8,7 8,15 3,15 3,7"></polygon></svg></td>
  310. <td class="sign leechers"><svg width="11" height="15" fill="white" class="tooltip" alt="Leechers" title="Leechers"><polygon points="0,8 5.5,15 11,8 8,8 8,0 3,0 3,8"></polygon></svg></td>
  311. </tr>
  312. <?
  313. if ($TopVotes === false) { ?>
  314. <tr>
  315. <td colspan="7" class="center">Server is busy processing another top list request. Please try again in a minute.</td>
  316. </tr>
  317. <?
  318. } elseif (count($TopVotes) === 0) { ?>
  319. <tr>
  320. <td colspan="7" class="center">No torrents were found that meet your criteria.</td>
  321. </tr>
  322. <?
  323. } else {
  324. echo $TorrentTable;
  325. }
  326. ?>
  327. </table>
  328. </div>
  329. <?
  330. View::show_footer();
  331. ?>