BioTorrents.de’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.

private.php 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <?php
  2. Text::$TOC = true;
  3. $NewsCount = 5;
  4. if (!$News = $Cache->get_value('news')) {
  5. $DB->query("
  6. SELECT
  7. ID,
  8. Title,
  9. Body,
  10. Time
  11. FROM news
  12. ORDER BY Time DESC
  13. LIMIT $NewsCount");
  14. $News = $DB->to_array(false, MYSQLI_NUM, false);
  15. $Cache->cache_value('news', $News, 3600 * 24 * 30);
  16. $Cache->cache_value('news_latest_id', $News[0][0], 0);
  17. $Cache->cache_value('news_latest_title', $News[0][1], 0);
  18. }
  19. if ($LoggedUser['LastReadNews'] != $News[0][0] && count($News) > 0) {
  20. $Cache->begin_transaction("user_info_heavy_$UserID");
  21. $Cache->update_row(false, array('LastReadNews' => $News[0][0]));
  22. $Cache->commit_transaction(0);
  23. $DB->query("
  24. UPDATE users_info
  25. SET LastReadNews = '".$News[0][0]."'
  26. WHERE UserID = $UserID");
  27. $LoggedUser['LastReadNews'] = $News[0][0];
  28. }
  29. View::show_header('News', 'bbcode,news_ajax');
  30. ?>
  31. <div class="thin">
  32. <div class="sidebar">
  33. <?
  34. if (check_perms('users_mod')) {
  35. ?>
  36. <div class="box">
  37. <div class="head colhead_dark">
  38. <strong><a href="staffblog.php">Latest staff blog posts</a></strong>
  39. </div>
  40. <?
  41. if (($Blog = $Cache->get_value('staff_blog')) === false) {
  42. $DB->query("
  43. SELECT
  44. b.ID,
  45. um.Username,
  46. b.Title,
  47. b.Body,
  48. b.Time
  49. FROM staff_blog AS b
  50. LEFT JOIN users_main AS um ON b.UserID = um.ID
  51. ORDER BY Time DESC");
  52. $Blog = $DB->to_array(false, MYSQLI_NUM);
  53. $Cache->cache_value('staff_blog', $Blog, 1209600);
  54. }
  55. if (($SBlogReadTime = $Cache->get_value('staff_blog_read_'.$LoggedUser['ID'])) === false) {
  56. $DB->query("
  57. SELECT Time
  58. FROM staff_blog_visits
  59. WHERE UserID = ".$LoggedUser['ID']);
  60. if (list($SBlogReadTime) = $DB->next_record()) {
  61. $SBlogReadTime = strtotime($SBlogReadTime);
  62. } else {
  63. $SBlogReadTime = 0;
  64. }
  65. $Cache->cache_value('staff_blog_read_'.$LoggedUser['ID'], $SBlogReadTime, 1209600);
  66. }
  67. ?>
  68. <ul class="stats nobullet">
  69. <?
  70. $End = min(count($Blog), 5);
  71. for ($i = 0; $i < $End; $i++) {
  72. list($BlogID, $Author, $Title, $Body, $BlogTime) = $Blog[$i];
  73. $BlogTime = strtotime($BlogTime);
  74. ?>
  75. <li>
  76. <?=$SBlogReadTime < $BlogTime ? '<strong>' : ''?><?=($i + 1)?>.
  77. <a href="staffblog.php#blog<?=$BlogID?>"><?=$Title?></a>
  78. <?=$SBlogReadTime < $BlogTime ? '</strong>' : ''?>
  79. </li>
  80. <?
  81. }
  82. ?>
  83. </ul>
  84. </div>
  85. <? } ?>
  86. <div class="box">
  87. <div class="head colhead_dark"><strong><a href="blog.php">Latest blog posts</a></strong></div>
  88. <?
  89. if (($Blog = $Cache->get_value('blog')) === false) {
  90. $DB->query("
  91. SELECT
  92. b.ID,
  93. um.Username,
  94. b.UserID,
  95. b.Title,
  96. b.Body,
  97. b.Time,
  98. b.ThreadID
  99. FROM blog AS b
  100. LEFT JOIN users_main AS um ON b.UserID = um.ID
  101. ORDER BY Time DESC
  102. LIMIT 20");
  103. $Blog = $DB->to_array();
  104. $Cache->cache_value('blog', $Blog, 1209600);
  105. }
  106. ?>
  107. <ul class="stats nobullet">
  108. <?
  109. if (count($Blog) < 5) {
  110. $Limit = count($Blog);
  111. } else {
  112. $Limit = 5;
  113. }
  114. for ($i = 0; $i < $Limit; $i++) {
  115. list($BlogID, $Author, $AuthorID, $Title, $Body, $BlogTime, $ThreadID) = $Blog[$i];
  116. ?>
  117. <li>
  118. <?=($i + 1)?>. <a href="blog.php#blog<?=$BlogID?>"><?=$Title?></a>
  119. </li>
  120. <?
  121. }
  122. ?>
  123. </ul>
  124. </div>
  125. <?
  126. if (($Freeleeches = $Cache->get_value('shop_freeleech_list')) === false) {
  127. $DB->query("
  128. SELECT
  129. TorrentID,
  130. UNIX_TIMESTAMP(ExpiryTime),
  131. COALESCE(NULLIF(Name,''), NULLIF(NameRJ,''), NameJP) AS Name,
  132. WikiImage
  133. FROM shop_freeleeches AS sf
  134. LEFT JOIN torrents AS t on sf.TorrentID=t.ID
  135. LEFT JOIN torrents_group AS tg ON tg.ID=t.GroupID
  136. ORDER BY ExpiryTime ASC
  137. LIMIT 10");
  138. $Freeleeches = $DB->to_array();
  139. $Cache->cache_value('shop_freeleech_list', $Freeleeches, 1209600);
  140. }
  141. if (count($Freeleeches)) {
  142. ?>
  143. <div class="box">
  144. <div class="head colhead_dark"><strong><a href="torrents.php?freetorrent=1&order_by=seeders&order_way=asc">Freeleeches</a></strong></div>
  145. <ul class="stats nobullet">
  146. <?
  147. for ($i = 0; $i < count($Freeleeches); $i++) {
  148. list($ID, $ExpiryTime, $Name, $Image) = $Freeleeches[$i];
  149. if ($ExpiryTime < time()) { continue; }
  150. $DisplayTime = '('.str_replace(['year','month','week','day','hour','min','Just now','s',' '],['y','M','w','d','h','m','0m'],time_diff($ExpiryTime, 1, false)).') ';
  151. $DisplayName = '<a href="torrents.php?torrentid='.$ID.'"';
  152. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  153. $DisplayName .= ' data-cover="'.ImageTools::process($Image, 'thumb').'"';
  154. }
  155. $DisplayName .= '>'.$Name.'</a>';
  156. ?>
  157. <li>
  158. <strong class="fl_time"><?=$DisplayTime?></strong>
  159. <?=$DisplayName?>
  160. </li>
  161. <?
  162. }
  163. ?>
  164. </ul>
  165. </div>
  166. <?
  167. }
  168. ?>
  169. <!-- Stats -->
  170. <div class="box">
  171. <div class="head colhead_dark"><strong>Stats</strong></div>
  172. <ul class="stats nobullet">
  173. <? if (USER_LIMIT > 0) { ?>
  174. <li>Maximum users: <?=number_format(USER_LIMIT) ?></li>
  175. <?
  176. }
  177. if (($UserCount = $Cache->get_value('stats_user_count')) === false) {
  178. $DB->query("
  179. SELECT COUNT(ID)
  180. FROM users_main
  181. WHERE Enabled = '1'");
  182. list($UserCount) = $DB->next_record();
  183. $Cache->cache_value('stats_user_count', $UserCount, 86400);
  184. }
  185. $UserCount = (int)$UserCount;
  186. ?>
  187. <li>Enabled users: <?=number_format($UserCount)?> <a href="stats.php?action=users" class="brackets">Details</a></li>
  188. <?
  189. if (($UserStats = $Cache->get_value('stats_users')) === false) {
  190. $DB->query("
  191. SELECT COUNT(ID)
  192. FROM users_main
  193. WHERE Enabled = '1'
  194. AND LastAccess > '".time_minus(3600 * 24)."'");
  195. list($UserStats['Day']) = $DB->next_record();
  196. $DB->query("
  197. SELECT COUNT(ID)
  198. FROM users_main
  199. WHERE Enabled = '1'
  200. AND LastAccess > '".time_minus(3600 * 24 * 7)."'");
  201. list($UserStats['Week']) = $DB->next_record();
  202. $DB->query("
  203. SELECT COUNT(ID)
  204. FROM users_main
  205. WHERE Enabled = '1'
  206. AND LastAccess > '".time_minus(3600 * 24 * 30)."'");
  207. list($UserStats['Month']) = $DB->next_record();
  208. $Cache->cache_value('stats_users', $UserStats, 0);
  209. }
  210. ?>
  211. <li>Users active today: <?=number_format($UserStats['Day'])?> (<?=number_format($UserStats['Day'] / $UserCount * 100, 2)?>%)</li>
  212. <li>Users active this week: <?=number_format($UserStats['Week'])?> (<?=number_format($UserStats['Week'] / $UserCount * 100, 2)?>%)</li>
  213. <li>Users active this month: <?=number_format($UserStats['Month'])?> (<?=number_format($UserStats['Month'] / $UserCount * 100, 2)?>%)</li>
  214. <?
  215. if (($TorrentCount = $Cache->get_value('stats_torrent_count')) === false) {
  216. $DB->query("
  217. SELECT COUNT(ID)
  218. FROM torrents");
  219. list($TorrentCount) = $DB->next_record();
  220. $Cache->cache_value('stats_torrent_count', $TorrentCount, 86400); // 1 day cache
  221. }
  222. if (($GroupCount = $Cache->get_value('stats_group_count')) === false) {
  223. $DB->query("
  224. SELECT COUNT(ID)
  225. FROM torrents_group");
  226. list($GroupCount) = $DB->next_record();
  227. $Cache->cache_value('stats_group_count', $GroupCount, 86400); // 1 day cache
  228. }
  229. if (($TorrentSizeTotal = $Cache->get_value('stats_torrent_size_total')) === false) {
  230. $DB->query("
  231. SELECT SUM(Size)
  232. FROM torrents");
  233. list($TorrentSizeTotal) = $DB->next_record();
  234. $Cache->cache_value('stats_torrent_size_total', $TorrentSizeTotal, 86400); // 1 day cache
  235. }
  236. ?>
  237. <li>Total Size of Torrents: <?=Format::get_size($TorrentSizeTotal)?> </li>
  238. <?
  239. if (($ArtistCount = $Cache->get_value('stats_artist_count')) === false) {
  240. $DB->query("
  241. SELECT COUNT(ArtistID)
  242. FROM artists_group");
  243. list($ArtistCount) = $DB->next_record();
  244. $Cache->cache_value('stats_artist_count', $ArtistCount, 86400); // 1 day cache
  245. }
  246. ?>
  247. <li>Torrents: <?=number_format($TorrentCount)?></li>
  248. <li>Torrent Groups: <?=number_format($GroupCount)?></li>
  249. <li>Artists: <?=number_format($ArtistCount)?></li>
  250. <?
  251. // End Torrent Stats
  252. if (($RequestStats = $Cache->get_value('stats_requests')) === false) {
  253. $DB->query("
  254. SELECT COUNT(ID)
  255. FROM requests");
  256. list($RequestCount) = $DB->next_record();
  257. $DB->query("
  258. SELECT COUNT(ID)
  259. FROM requests
  260. WHERE FillerID > 0");
  261. list($FilledCount) = $DB->next_record();
  262. $Cache->cache_value('stats_requests', array($RequestCount, $FilledCount), 11280);
  263. } else {
  264. list($RequestCount, $FilledCount) = $RequestStats;
  265. }
  266. // Do not divide by zero
  267. if ($RequestCount > 0) {
  268. $RequestsFilledPercent = $FilledCount / $RequestCount * 100;
  269. } else {
  270. $RequestsFilledPercent = 0;
  271. }
  272. ?>
  273. <li>Requests: <?=number_format($RequestCount)?> (<?=number_format($RequestsFilledPercent, 2)?>% filled)</li>
  274. <?
  275. if ($SnatchStats = $Cache->get_value('stats_snatches')) {
  276. ?>
  277. <li>Snatches: <?=number_format($SnatchStats)?></li>
  278. <?
  279. }
  280. if (($PeerStats = $Cache->get_value('stats_peers')) === false) {
  281. // Cache lock!
  282. $PeerStatsLocked = $Cache->get_value('stats_peers_lock');
  283. if (!$PeerStatsLocked) {
  284. $Cache->cache_value('stats_peers_lock', 1, 30);
  285. $DB->query("
  286. SELECT IF(remaining=0,'Seeding','Leeching') AS Type, COUNT(uid)
  287. FROM xbt_files_users
  288. WHERE active = 1
  289. GROUP BY Type");
  290. $PeerCount = $DB->to_array(0, MYSQLI_NUM, false);
  291. $SeederCount = $PeerCount['Seeding'][1] ?: 0;
  292. $LeecherCount = $PeerCount['Leeching'][1] ?: 0;
  293. $Cache->cache_value('stats_peers', array($LeecherCount, $SeederCount), 604800); // 1 week cache
  294. $Cache->delete_value('stats_peers_lock');
  295. }
  296. } else {
  297. $PeerStatsLocked = false;
  298. list($LeecherCount, $SeederCount) = $PeerStats;
  299. }
  300. if (!$PeerStatsLocked) {
  301. $Ratio = Format::get_ratio_html($SeederCount, $LeecherCount);
  302. $PeerCount = number_format($SeederCount + $LeecherCount);
  303. $SeederCount = number_format($SeederCount);
  304. $LeecherCount = number_format($LeecherCount);
  305. } else {
  306. $PeerCount = $SeederCount = $LeecherCount = $Ratio = 'Server busy';
  307. }
  308. ?>
  309. <li>Peers: <?=$PeerCount?></li>
  310. <li>Seeders: <?=$SeederCount?></li>
  311. <li>Leechers: <?=$LeecherCount?></li>
  312. <li>Seeder/leecher ratio: <?=$Ratio?></li>
  313. </ul>
  314. </div>
  315. <!-- Polls -->
  316. <?
  317. if (($TopicID = $Cache->get_value('polls_featured')) === false) {
  318. $DB->query("
  319. SELECT TopicID
  320. FROM forums_polls
  321. ORDER BY Featured DESC
  322. LIMIT 1");
  323. list($TopicID) = $DB->next_record();
  324. $Cache->cache_value('polls_featured', $TopicID, 0);
  325. }
  326. if ($TopicID) {
  327. if (($Poll = $Cache->get_value("polls_$TopicID")) === false) {
  328. $DB->query("
  329. SELECT Question, Answers, Featured, Closed
  330. FROM forums_polls
  331. WHERE TopicID = '$TopicID'");
  332. list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
  333. $Answers = unserialize($Answers);
  334. $DB->query("
  335. SELECT Vote, COUNT(UserID)
  336. FROM forums_polls_votes
  337. WHERE TopicID = '$TopicID'
  338. AND Vote != '0'
  339. GROUP BY Vote");
  340. $VoteArray = $DB->to_array(false, MYSQLI_NUM);
  341. $Votes = [];
  342. foreach ($VoteArray as $VoteSet) {
  343. list($Key,$Value) = $VoteSet;
  344. $Votes[$Key] = $Value;
  345. }
  346. for ($i = 1, $il = count($Answers); $i <= $il; ++$i) {
  347. if (!isset($Votes[$i])) {
  348. $Votes[$i] = 0;
  349. }
  350. }
  351. $Cache->cache_value("polls_$TopicID", array($Question, $Answers, $Votes, $Featured, $Closed), 0);
  352. } else {
  353. list($Question, $Answers, $Votes, $Featured, $Closed) = $Poll;
  354. }
  355. if (!empty($Votes)) {
  356. $TotalVotes = array_sum($Votes);
  357. $MaxVotes = max($Votes);
  358. } else {
  359. $TotalVotes = 0;
  360. $MaxVotes = 0;
  361. }
  362. $DB->query("
  363. SELECT Vote
  364. FROM forums_polls_votes
  365. WHERE UserID = '".$LoggedUser['ID']."'
  366. AND TopicID = '$TopicID'");
  367. list($UserResponse) = $DB->next_record();
  368. ?>
  369. <div class="box">
  370. <div class="head colhead_dark"><strong>Poll<? if ($Closed) { echo ' [Closed]'; } ?></strong></div>
  371. <div class="pad">
  372. <p><strong><?=display_str($Question)?></strong></p>
  373. <? if ($UserResponse !== null || $Closed) { ?>
  374. <ul class="poll nobullet">
  375. <? foreach ($Answers as $i => $Answer) {
  376. if ($TotalVotes > 0) {
  377. $Ratio = $Votes[$i] / $MaxVotes;
  378. $Percent = $Votes[$i] / $TotalVotes;
  379. } else {
  380. $Ratio = 0;
  381. $Percent = 0;
  382. }
  383. ?> <li<?=((!empty($UserResponse) && ($UserResponse == $i))?' class="poll_your_answer"':'')?>><?=display_str($Answers[$i])?> (<?=number_format($Percent * 100, 2)?>%)</li>
  384. <li class="graph">
  385. <span class="center_poll" style="width: <?=round($Ratio * 140)?>px;"></span>
  386. <br />
  387. </li>
  388. <? } ?>
  389. </ul>
  390. <strong>Votes:</strong> <?=number_format($TotalVotes)?><br />
  391. <? } else { ?>
  392. <div id="poll_container">
  393. <form class="vote_form" name="poll" id="poll" action="">
  394. <input type="hidden" name="action" value="poll" />
  395. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  396. <input type="hidden" name="topicid" value="<?=$TopicID?>" />
  397. <? foreach ($Answers as $i => $Answer) { ?>
  398. <input type="radio" name="vote" id="answer_<?=$i?>" value="<?=$i?>" />
  399. <label for="answer_<?=$i?>"><?=display_str($Answers[$i])?></label><br />
  400. <? } ?>
  401. <br /><input type="radio" name="vote" id="answer_0" value="0" /> <label for="answer_0">Blank&#8202;&mdash;&#8202;Show the results!</label><br /><br />
  402. <input type="button" onclick="ajax.post('index.php', 'poll', function(response) { $('#poll_container').raw().innerHTML = response } );" value="Vote" />
  403. </form>
  404. </div>
  405. <? } ?>
  406. <br /><strong>Topic:</strong> <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>">Visit</a>
  407. </div>
  408. </div>
  409. <?
  410. }
  411. // polls();
  412. ?>
  413. </div>
  414. <div class="main_column">
  415. <?
  416. $Recommend = $Cache->get_value('recommend');
  417. $Recommend_artists = $Cache->get_value('recommend_artists');
  418. if (!is_array($Recommend) || !is_array($Recommend_artists)) {
  419. $DB->query("
  420. SELECT
  421. tr.GroupID,
  422. tr.UserID,
  423. u.Username,
  424. tg.Name,
  425. tg.TagList
  426. FROM torrents_recommended AS tr
  427. JOIN torrents_group AS tg ON tg.ID = tr.GroupID
  428. LEFT JOIN users_main AS u ON u.ID = tr.UserID
  429. ORDER BY tr.Time DESC
  430. LIMIT 10");
  431. $Recommend = $DB->to_array();
  432. $Cache->cache_value('recommend', $Recommend, 1209600);
  433. $Recommend_artists = Artists::get_artists($DB->collect('GroupID'));
  434. $Cache->cache_value('recommend_artists', $Recommend_artists, 1209600);
  435. }
  436. if (count($Recommend) >= 4) {
  437. $Cache->increment('usage_index');
  438. ?>
  439. <div class="box" id="recommended">
  440. <div class="head colhead_dark">
  441. <strong>Latest Vanity House additions</strong>
  442. <a data-toggle-target="#vanityhouse", data-toggle-replace="Hide" class="brackets">Show</a>
  443. </div>
  444. <table class="torrent_table hidden" id="vanityhouse">
  445. <?
  446. foreach ($Recommend as $Recommendations) {
  447. list($GroupID, $UserID, $Username, $GroupName, $TagList) = $Recommendations;
  448. $TagsStr = '';
  449. if ($TagList) {
  450. // No vanity.house tag.
  451. $Tags = explode(' ', str_replace('_', '.', $TagList));
  452. $TagLinks = [];
  453. foreach ($Tags as $Tag) {
  454. if ($Tag == 'vanity.house') {
  455. continue;
  456. }
  457. $TagLinks[] = "<a href=\"torrents.php?action=basic&amp;taglist=$Tag\">$Tag</a> ";
  458. }
  459. $TagStr = "<br />\n<div class=\"tags\">".implode(', ', $TagLinks).'</div>';
  460. }
  461. ?>
  462. <tr>
  463. <td>
  464. <?=Artists::display_artists($Recommend_artists[$GroupID]) ?>
  465. <a href="torrents.php?id=<?=$GroupID?>"><?=$GroupName?></a> (by <?=Users::format_username($UserID, false, false, false)?>)
  466. <?=$TagStr?>
  467. </td>
  468. </tr>
  469. <? } ?>
  470. </table>
  471. </div>
  472. <!-- END recommendations section -->
  473. <?
  474. }
  475. $Count = 0;
  476. foreach ($News as $NewsItem) {
  477. list($NewsID, $Title, $Body, $NewsTime) = $NewsItem;
  478. if (strtotime($NewsTime) > time()) {
  479. continue;
  480. }
  481. ?>
  482. <div id="news<?=$NewsID?>" class="box news_post">
  483. <div class="head">
  484. <strong><?=Text::full_format($Title)?></strong> <?=time_diff($NewsTime);?>
  485. <? if (check_perms('admin_manage_news')) { ?>
  486. - <a href="tools.php?action=editnews&amp;id=<?=$NewsID?>" class="brackets">Edit</a>
  487. <? } ?>
  488. <span class="float_right"><a data-toggle-target="#newsbody<?=$NewsID?>" data-toggle-replace="Show" class="brackets">Hide</a></span>
  489. </div>
  490. <div id="newsbody<?=$NewsID?>" class="pad"><?=Text::full_format($Body)?></div>
  491. </div>
  492. <?
  493. if (++$Count > ($NewsCount - 1)) {
  494. break;
  495. }
  496. }
  497. ?>
  498. <div id="more_news" class="box">
  499. <div class="head">
  500. <em><span><a href="#" onclick="news_ajax(event, 3, <?=$NewsCount?>, <?=check_perms('admin_manage_news') ? 1 : 0; ?>); return false;">Click to load more news</a>.</span> To browse old news posts, <a href="forums.php?action=viewforum&amp;forumid=<?=ANNOUNCEMENT_FORUM_ID?>">click here</a>.</em>
  501. </div>
  502. </div>
  503. </div>
  504. </div>
  505. <?
  506. View::show_footer(array('disclaimer'=>true));
  507. function contest() {
  508. global $DB, $Cache, $LoggedUser;
  509. list($Contest, $TotalPoints) = $Cache->get_value('contest');
  510. if (!$Contest) {
  511. $DB->query("
  512. SELECT
  513. UserID,
  514. SUM(Points),
  515. Username
  516. FROM users_points AS up
  517. JOIN users_main AS um ON um.ID = up.UserID
  518. GROUP BY UserID
  519. ORDER BY SUM(Points) DESC
  520. LIMIT 20");
  521. $Contest = $DB->to_array();
  522. $DB->query("
  523. SELECT SUM(Points)
  524. FROM users_points");
  525. list($TotalPoints) = $DB->next_record();
  526. $Cache->cache_value('contest', array($Contest, $TotalPoints), 600);
  527. }
  528. ?>
  529. <!-- Contest Section -->
  530. <div class="box box_contest">
  531. <div class="head colhead_dark"><strong>Quality time scoreboard</strong></div>
  532. <div class="pad">
  533. <ol style="padding-left: 5px;">
  534. <?
  535. foreach ($Contest as $User) {
  536. list($UserID, $Points, $Username) = $User;
  537. ?>
  538. <li><?=Users::format_username($UserID, false, false, false)?> (<?=number_format($Points)?>)</li>
  539. <? } ?>
  540. </ol>
  541. Total uploads: <?=$TotalPoints?><br />
  542. <a href="index.php?action=scoreboard">Full scoreboard</a>
  543. </div>
  544. </div>
  545. <!-- END contest Section -->
  546. <?
  547. } // contest()
  548. ?>