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.

private.php 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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][0]) > 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. Name,
  132. NameRJ,
  133. NameJP,
  134. WikiImage
  135. FROM shop_freeleeches AS sf
  136. LEFT JOIN torrents AS t on sf.TorrentID=t.ID
  137. LEFT JOIN torrents_group AS tg ON tg.ID=t.GroupID
  138. ORDER BY ExpiryTime ASC
  139. LIMIT 10");
  140. $Freeleeches = $DB->to_array();
  141. $Cache->cache_value('shop_freeleech_list', $Freeleeches, 1209600);
  142. }
  143. if (count($Freeleeches)) {
  144. ?>
  145. <div class="box">
  146. <div class="head colhead_dark"><strong><a href="torrents.php?freetorrent=1&order_by=seeders&order_way=asc">Freeleeches</a></strong></div>
  147. <ul class="stats nobullet">
  148. <?
  149. for ($i = 0; $i < count($Freeleeches); $i++) {
  150. list($ID, $ExpiryTime, $Name, $NameRJ, $NameJP, $Image) = $Freeleeches[$i];
  151. if ($ExpiryTime < time()) { continue; }
  152. $DisplayTime = '('.str_replace(['week','day','hour','min','Just now','s',' '],['w','d','h','m','0m'],time_diff($ExpiryTime, 1, false)).') ';
  153. $DisplayName = '<a href="torrents.php?torrentid='.$ID.'"';
  154. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  155. $DisplayName .= " onmouseover=\"getCover(event)\" data-cover=\"".ImageTools::process($Image)."\" onmouseleave=\"ungetCover(event)\"";
  156. }
  157. $DisplayName .= '>'.($Name?$Name:($NameRJ?$NameRJ:$NameJP)).'</a>';
  158. ?>
  159. <li>
  160. <strong class="fl_time"><?=$DisplayTime?></strong>
  161. <?=$DisplayName?>
  162. </li>
  163. <?
  164. }
  165. ?>
  166. </ul>
  167. </div>
  168. <?
  169. }
  170. ?>
  171. <div class="box">
  172. <div class="head colhead_dark"><strong>Stats</strong></div>
  173. <ul class="stats nobullet">
  174. <? if (USER_LIMIT > 0) { ?>
  175. <li>Maximum users: <?=number_format(USER_LIMIT) ?></li>
  176. <?
  177. }
  178. if (($UserCount = $Cache->get_value('stats_user_count')) === false) {
  179. $DB->query("
  180. SELECT COUNT(ID)
  181. FROM users_main
  182. WHERE Enabled = '1'");
  183. list($UserCount) = $DB->next_record();
  184. $Cache->cache_value('stats_user_count', $UserCount, 86400);
  185. }
  186. $UserCount = (int)$UserCount;
  187. ?>
  188. <li>Enabled users: <?=number_format($UserCount)?> <a href="stats.php?action=users" class="brackets">Details</a></li>
  189. <?
  190. if (($UserStats = $Cache->get_value('stats_users')) === false) {
  191. $DB->query("
  192. SELECT COUNT(ID)
  193. FROM users_main
  194. WHERE Enabled = '1'
  195. AND LastAccess > '".time_minus(3600 * 24)."'");
  196. list($UserStats['Day']) = $DB->next_record();
  197. $DB->query("
  198. SELECT COUNT(ID)
  199. FROM users_main
  200. WHERE Enabled = '1'
  201. AND LastAccess > '".time_minus(3600 * 24 * 7)."'");
  202. list($UserStats['Week']) = $DB->next_record();
  203. $DB->query("
  204. SELECT COUNT(ID)
  205. FROM users_main
  206. WHERE Enabled = '1'
  207. AND LastAccess > '".time_minus(3600 * 24 * 30)."'");
  208. list($UserStats['Month']) = $DB->next_record();
  209. $Cache->cache_value('stats_users', $UserStats, 0);
  210. }
  211. ?>
  212. <li>Users active today: <?=number_format($UserStats['Day'])?> (<?=number_format($UserStats['Day'] / $UserCount * 100, 2)?>%)</li>
  213. <li>Users active this week: <?=number_format($UserStats['Week'])?> (<?=number_format($UserStats['Week'] / $UserCount * 100, 2)?>%)</li>
  214. <li>Users active this month: <?=number_format($UserStats['Month'])?> (<?=number_format($UserStats['Month'] / $UserCount * 100, 2)?>%)</li>
  215. <?
  216. if (($TorrentCount = $Cache->get_value('stats_torrent_count')) === false) {
  217. $DB->query("
  218. SELECT COUNT(ID)
  219. FROM torrents");
  220. list($TorrentCount) = $DB->next_record();
  221. $Cache->cache_value('stats_torrent_count', $TorrentCount, 86400); // 1 day cache
  222. }
  223. if (($GroupCount = $Cache->get_value('stats_group_count')) === false) {
  224. $DB->query("
  225. SELECT COUNT(ID)
  226. FROM torrents_group");
  227. list($GroupCount) = $DB->next_record();
  228. $Cache->cache_value('stats_group_count', $GroupCount, 86400); // 1 day cache
  229. }
  230. if (($TorrentSizeTotal = $Cache->get_value('stats_torrent_size_total')) === false) {
  231. $DB->query("
  232. SELECT SUM(Size)
  233. FROM torrents");
  234. list($TorrentSizeTotal) = $DB->next_record();
  235. $Cache->cache_value('stats_torrent_size_total', $TorrentSizeTotal, 86400); // 1 day cache
  236. }
  237. ?>
  238. <li>Total Size of Torrents: <?=Format::get_size($TorrentSizeTotal)?> </li>
  239. <?
  240. if (($ArtistCount = $Cache->get_value('stats_artist_count')) === false) {
  241. $DB->query("
  242. SELECT COUNT(ArtistID)
  243. FROM artists_group");
  244. list($ArtistCount) = $DB->next_record();
  245. $Cache->cache_value('stats_artist_count', $ArtistCount, 86400); // 1 day cache
  246. }
  247. ?>
  248. <li>Torrents: <?=number_format($TorrentCount)?></li>
  249. <li>Torrent Groups: <?=number_format($GroupCount)?></li>
  250. <li>Artists: <?=number_format($ArtistCount)?></li>
  251. <?
  252. //End Torrent Stats
  253. if (($RequestStats = $Cache->get_value('stats_requests')) === false) {
  254. $DB->query("
  255. SELECT COUNT(ID)
  256. FROM requests");
  257. list($RequestCount) = $DB->next_record();
  258. $DB->query("
  259. SELECT COUNT(ID)
  260. FROM requests
  261. WHERE FillerID > 0");
  262. list($FilledCount) = $DB->next_record();
  263. $Cache->cache_value('stats_requests', array($RequestCount, $FilledCount), 11280);
  264. } else {
  265. list($RequestCount, $FilledCount) = $RequestStats;
  266. }
  267. // do not divide by zero
  268. if ($RequestCount > 0) {
  269. $RequestsFilledPercent = $FilledCount / $RequestCount * 100;
  270. } else {
  271. $RequestsFilledPercent = 0;
  272. }
  273. ?>
  274. <li>Requests: <?=number_format($RequestCount)?> (<?=number_format($RequestsFilledPercent, 2)?>% filled)</li>
  275. <?
  276. if ($SnatchStats = $Cache->get_value('stats_snatches')) {
  277. ?>
  278. <li>Snatches: <?=number_format($SnatchStats)?></li>
  279. <?
  280. }
  281. if (($PeerStats = $Cache->get_value('stats_peers')) === false) {
  282. //Cache lock!
  283. $PeerStatsLocked = $Cache->get_value('stats_peers_lock');
  284. if (!$PeerStatsLocked) {
  285. $Cache->cache_value('stats_peers_lock', 1, 30);
  286. $DB->query("
  287. SELECT IF(remaining=0,'Seeding','Leeching') AS Type, COUNT(uid)
  288. FROM xbt_files_users
  289. WHERE active = 1
  290. GROUP BY Type");
  291. $PeerCount = $DB->to_array(0, MYSQLI_NUM, false);
  292. $SeederCount = $PeerCount['Seeding'][1] ?: 0;
  293. $LeecherCount = $PeerCount['Leeching'][1] ?: 0;
  294. $Cache->cache_value('stats_peers', array($LeecherCount, $SeederCount), 604800); // 1 week cache
  295. $Cache->delete_value('stats_peers_lock');
  296. }
  297. } else {
  298. $PeerStatsLocked = false;
  299. list($LeecherCount, $SeederCount) = $PeerStats;
  300. }
  301. if (!$PeerStatsLocked) {
  302. $Ratio = Format::get_ratio_html($SeederCount, $LeecherCount);
  303. $PeerCount = number_format($SeederCount + $LeecherCount);
  304. $SeederCount = number_format($SeederCount);
  305. $LeecherCount = number_format($LeecherCount);
  306. } else {
  307. $PeerCount = $SeederCount = $LeecherCount = $Ratio = 'Server busy';
  308. }
  309. ?>
  310. <li>Peers: <?=$PeerCount?></li>
  311. <li>Seeders: <?=$SeederCount?></li>
  312. <li>Leechers: <?=$LeecherCount?></li>
  313. <li>Seeder/leecher ratio: <?=$Ratio?></li>
  314. </ul>
  315. </div>
  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 = array();
  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 = array();
  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 style="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=10">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. ?>