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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. 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(['week','day','hour','min','Just now','s',' '],['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 .= " onmouseover=\"getCover(event)\" data-cover=\"".ImageTools::process($Image)."\" onmouseleave=\"ungetCover(event)\"";
  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. <div class="box">
  170. <div class="head colhead_dark"><strong>Stats</strong></div>
  171. <ul class="stats nobullet">
  172. <? if (USER_LIMIT > 0) { ?>
  173. <li>Maximum users: <?=number_format(USER_LIMIT) ?></li>
  174. <?
  175. }
  176. if (($UserCount = $Cache->get_value('stats_user_count')) === false) {
  177. $DB->query("
  178. SELECT COUNT(ID)
  179. FROM users_main
  180. WHERE Enabled = '1'");
  181. list($UserCount) = $DB->next_record();
  182. $Cache->cache_value('stats_user_count', $UserCount, 86400);
  183. }
  184. $UserCount = (int)$UserCount;
  185. ?>
  186. <li>Enabled users: <?=number_format($UserCount)?> <a href="stats.php?action=users" class="brackets">Details</a></li>
  187. <?
  188. if (($UserStats = $Cache->get_value('stats_users')) === false) {
  189. $DB->query("
  190. SELECT COUNT(ID)
  191. FROM users_main
  192. WHERE Enabled = '1'
  193. AND LastAccess > '".time_minus(3600 * 24)."'");
  194. list($UserStats['Day']) = $DB->next_record();
  195. $DB->query("
  196. SELECT COUNT(ID)
  197. FROM users_main
  198. WHERE Enabled = '1'
  199. AND LastAccess > '".time_minus(3600 * 24 * 7)."'");
  200. list($UserStats['Week']) = $DB->next_record();
  201. $DB->query("
  202. SELECT COUNT(ID)
  203. FROM users_main
  204. WHERE Enabled = '1'
  205. AND LastAccess > '".time_minus(3600 * 24 * 30)."'");
  206. list($UserStats['Month']) = $DB->next_record();
  207. $Cache->cache_value('stats_users', $UserStats, 0);
  208. }
  209. ?>
  210. <li>Users active today: <?=number_format($UserStats['Day'])?> (<?=number_format($UserStats['Day'] / $UserCount * 100, 2)?>%)</li>
  211. <li>Users active this week: <?=number_format($UserStats['Week'])?> (<?=number_format($UserStats['Week'] / $UserCount * 100, 2)?>%)</li>
  212. <li>Users active this month: <?=number_format($UserStats['Month'])?> (<?=number_format($UserStats['Month'] / $UserCount * 100, 2)?>%)</li>
  213. <?
  214. if (($TorrentCount = $Cache->get_value('stats_torrent_count')) === false) {
  215. $DB->query("
  216. SELECT COUNT(ID)
  217. FROM torrents");
  218. list($TorrentCount) = $DB->next_record();
  219. $Cache->cache_value('stats_torrent_count', $TorrentCount, 86400); // 1 day cache
  220. }
  221. if (($GroupCount = $Cache->get_value('stats_group_count')) === false) {
  222. $DB->query("
  223. SELECT COUNT(ID)
  224. FROM torrents_group");
  225. list($GroupCount) = $DB->next_record();
  226. $Cache->cache_value('stats_group_count', $GroupCount, 86400); // 1 day cache
  227. }
  228. if (($TorrentSizeTotal = $Cache->get_value('stats_torrent_size_total')) === false) {
  229. $DB->query("
  230. SELECT SUM(Size)
  231. FROM torrents");
  232. list($TorrentSizeTotal) = $DB->next_record();
  233. $Cache->cache_value('stats_torrent_size_total', $TorrentSizeTotal, 86400); // 1 day cache
  234. }
  235. ?>
  236. <li>Total Size of Torrents: <?=Format::get_size($TorrentSizeTotal)?> </li>
  237. <?
  238. if (($ArtistCount = $Cache->get_value('stats_artist_count')) === false) {
  239. $DB->query("
  240. SELECT COUNT(ArtistID)
  241. FROM artists_group");
  242. list($ArtistCount) = $DB->next_record();
  243. $Cache->cache_value('stats_artist_count', $ArtistCount, 86400); // 1 day cache
  244. }
  245. ?>
  246. <li>Torrents: <?=number_format($TorrentCount)?></li>
  247. <li>Torrent Groups: <?=number_format($GroupCount)?></li>
  248. <li>Artists: <?=number_format($ArtistCount)?></li>
  249. <?
  250. //End Torrent Stats
  251. if (($RequestStats = $Cache->get_value('stats_requests')) === false) {
  252. $DB->query("
  253. SELECT COUNT(ID)
  254. FROM requests");
  255. list($RequestCount) = $DB->next_record();
  256. $DB->query("
  257. SELECT COUNT(ID)
  258. FROM requests
  259. WHERE FillerID > 0");
  260. list($FilledCount) = $DB->next_record();
  261. $Cache->cache_value('stats_requests', array($RequestCount, $FilledCount), 11280);
  262. } else {
  263. list($RequestCount, $FilledCount) = $RequestStats;
  264. }
  265. // do not divide by zero
  266. if ($RequestCount > 0) {
  267. $RequestsFilledPercent = $FilledCount / $RequestCount * 100;
  268. } else {
  269. $RequestsFilledPercent = 0;
  270. }
  271. ?>
  272. <li>Requests: <?=number_format($RequestCount)?> (<?=number_format($RequestsFilledPercent, 2)?>% filled)</li>
  273. <?
  274. if ($SnatchStats = $Cache->get_value('stats_snatches')) {
  275. ?>
  276. <li>Snatches: <?=number_format($SnatchStats)?></li>
  277. <?
  278. }
  279. if (($PeerStats = $Cache->get_value('stats_peers')) === false) {
  280. //Cache lock!
  281. $PeerStatsLocked = $Cache->get_value('stats_peers_lock');
  282. if (!$PeerStatsLocked) {
  283. $Cache->cache_value('stats_peers_lock', 1, 30);
  284. $DB->query("
  285. SELECT IF(remaining=0,'Seeding','Leeching') AS Type, COUNT(uid)
  286. FROM xbt_files_users
  287. WHERE active = 1
  288. GROUP BY Type");
  289. $PeerCount = $DB->to_array(0, MYSQLI_NUM, false);
  290. $SeederCount = $PeerCount['Seeding'][1] ?: 0;
  291. $LeecherCount = $PeerCount['Leeching'][1] ?: 0;
  292. $Cache->cache_value('stats_peers', array($LeecherCount, $SeederCount), 604800); // 1 week cache
  293. $Cache->delete_value('stats_peers_lock');
  294. }
  295. } else {
  296. $PeerStatsLocked = false;
  297. list($LeecherCount, $SeederCount) = $PeerStats;
  298. }
  299. if (!$PeerStatsLocked) {
  300. $Ratio = Format::get_ratio_html($SeederCount, $LeecherCount);
  301. $PeerCount = number_format($SeederCount + $LeecherCount);
  302. $SeederCount = number_format($SeederCount);
  303. $LeecherCount = number_format($LeecherCount);
  304. } else {
  305. $PeerCount = $SeederCount = $LeecherCount = $Ratio = 'Server busy';
  306. }
  307. ?>
  308. <li>Peers: <?=$PeerCount?></li>
  309. <li>Seeders: <?=$SeederCount?></li>
  310. <li>Leechers: <?=$LeecherCount?></li>
  311. <li>Seeder/leecher ratio: <?=$Ratio?></li>
  312. </ul>
  313. </div>
  314. <?
  315. if (($TopicID = $Cache->get_value('polls_featured')) === false) {
  316. $DB->query("
  317. SELECT TopicID
  318. FROM forums_polls
  319. ORDER BY Featured DESC
  320. LIMIT 1");
  321. list($TopicID) = $DB->next_record();
  322. $Cache->cache_value('polls_featured', $TopicID, 0);
  323. }
  324. if ($TopicID) {
  325. if (($Poll = $Cache->get_value("polls_$TopicID")) === false) {
  326. $DB->query("
  327. SELECT Question, Answers, Featured, Closed
  328. FROM forums_polls
  329. WHERE TopicID = '$TopicID'");
  330. list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
  331. $Answers = unserialize($Answers);
  332. $DB->query("
  333. SELECT Vote, COUNT(UserID)
  334. FROM forums_polls_votes
  335. WHERE TopicID = '$TopicID'
  336. AND Vote != '0'
  337. GROUP BY Vote");
  338. $VoteArray = $DB->to_array(false, MYSQLI_NUM);
  339. $Votes = [];
  340. foreach ($VoteArray as $VoteSet) {
  341. list($Key,$Value) = $VoteSet;
  342. $Votes[$Key] = $Value;
  343. }
  344. for ($i = 1, $il = count($Answers); $i <= $il; ++$i) {
  345. if (!isset($Votes[$i])) {
  346. $Votes[$i] = 0;
  347. }
  348. }
  349. $Cache->cache_value("polls_$TopicID", array($Question, $Answers, $Votes, $Featured, $Closed), 0);
  350. } else {
  351. list($Question, $Answers, $Votes, $Featured, $Closed) = $Poll;
  352. }
  353. if (!empty($Votes)) {
  354. $TotalVotes = array_sum($Votes);
  355. $MaxVotes = max($Votes);
  356. } else {
  357. $TotalVotes = 0;
  358. $MaxVotes = 0;
  359. }
  360. $DB->query("
  361. SELECT Vote
  362. FROM forums_polls_votes
  363. WHERE UserID = '".$LoggedUser['ID']."'
  364. AND TopicID = '$TopicID'");
  365. list($UserResponse) = $DB->next_record();
  366. ?>
  367. <div class="box">
  368. <div class="head colhead_dark"><strong>Poll<? if ($Closed) { echo ' [Closed]'; } ?></strong></div>
  369. <div class="pad">
  370. <p><strong><?=display_str($Question)?></strong></p>
  371. <? if ($UserResponse !== null || $Closed) { ?>
  372. <ul class="poll nobullet">
  373. <? foreach ($Answers as $i => $Answer) {
  374. if ($TotalVotes > 0) {
  375. $Ratio = $Votes[$i] / $MaxVotes;
  376. $Percent = $Votes[$i] / $TotalVotes;
  377. } else {
  378. $Ratio = 0;
  379. $Percent = 0;
  380. }
  381. ?> <li<?=((!empty($UserResponse) && ($UserResponse == $i))?' class="poll_your_answer"':'')?>><?=display_str($Answers[$i])?> (<?=number_format($Percent * 100, 2)?>%)</li>
  382. <li class="graph">
  383. <span class="center_poll" style="width: <?=round($Ratio * 140)?>px;"></span>
  384. <br />
  385. </li>
  386. <? } ?>
  387. </ul>
  388. <strong>Votes:</strong> <?=number_format($TotalVotes)?><br />
  389. <? } else { ?>
  390. <div id="poll_container">
  391. <form class="vote_form" name="poll" id="poll" action="">
  392. <input type="hidden" name="action" value="poll" />
  393. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  394. <input type="hidden" name="topicid" value="<?=$TopicID?>" />
  395. <? foreach ($Answers as $i => $Answer) { ?>
  396. <input type="radio" name="vote" id="answer_<?=$i?>" value="<?=$i?>" />
  397. <label for="answer_<?=$i?>"><?=display_str($Answers[$i])?></label><br />
  398. <? } ?>
  399. <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 />
  400. <input type="button" onclick="ajax.post('index.php', 'poll', function(response) { $('#poll_container').raw().innerHTML = response } );" value="Vote" />
  401. </form>
  402. </div>
  403. <? } ?>
  404. <br /><strong>Topic:</strong> <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>">Visit</a>
  405. </div>
  406. </div>
  407. <?
  408. }
  409. //polls();
  410. ?>
  411. </div>
  412. <div class="main_column">
  413. <?
  414. $Recommend = $Cache->get_value('recommend');
  415. $Recommend_artists = $Cache->get_value('recommend_artists');
  416. if (!is_array($Recommend) || !is_array($Recommend_artists)) {
  417. $DB->query("
  418. SELECT
  419. tr.GroupID,
  420. tr.UserID,
  421. u.Username,
  422. tg.Name,
  423. tg.TagList
  424. FROM torrents_recommended AS tr
  425. JOIN torrents_group AS tg ON tg.ID = tr.GroupID
  426. LEFT JOIN users_main AS u ON u.ID = tr.UserID
  427. ORDER BY tr.Time DESC
  428. LIMIT 10");
  429. $Recommend = $DB->to_array();
  430. $Cache->cache_value('recommend', $Recommend, 1209600);
  431. $Recommend_artists = Artists::get_artists($DB->collect('GroupID'));
  432. $Cache->cache_value('recommend_artists', $Recommend_artists, 1209600);
  433. }
  434. if (count($Recommend) >= 4) {
  435. $Cache->increment('usage_index');
  436. ?>
  437. <div class="box" id="recommended">
  438. <div class="head colhead_dark">
  439. <strong>Latest Vanity House additions</strong>
  440. <a data-toggle-target="#vanityhouse", data-toggle-replace="Hide" class="brackets">Show</a>
  441. </div>
  442. <table class="torrent_table hidden" id="vanityhouse">
  443. <?
  444. foreach ($Recommend as $Recommendations) {
  445. list($GroupID, $UserID, $Username, $GroupName, $TagList) = $Recommendations;
  446. $TagsStr = '';
  447. if ($TagList) {
  448. // No vanity.house tag.
  449. $Tags = explode(' ', str_replace('_', '.', $TagList));
  450. $TagLinks = [];
  451. foreach ($Tags as $Tag) {
  452. if ($Tag == 'vanity.house') {
  453. continue;
  454. }
  455. $TagLinks[] = "<a href=\"torrents.php?action=basic&amp;taglist=$Tag\">$Tag</a> ";
  456. }
  457. $TagStr = "<br />\n<div class=\"tags\">".implode(', ', $TagLinks).'</div>';
  458. }
  459. ?>
  460. <tr>
  461. <td>
  462. <?=Artists::display_artists($Recommend_artists[$GroupID]) ?>
  463. <a href="torrents.php?id=<?=$GroupID?>"><?=$GroupName?></a> (by <?=Users::format_username($UserID, false, false, false)?>)
  464. <?=$TagStr?>
  465. </td>
  466. </tr>
  467. <? } ?>
  468. </table>
  469. </div>
  470. <!-- END recommendations section -->
  471. <?
  472. }
  473. $Count = 0;
  474. foreach ($News as $NewsItem) {
  475. list($NewsID, $Title, $Body, $NewsTime) = $NewsItem;
  476. if (strtotime($NewsTime) > time()) {
  477. continue;
  478. }
  479. ?>
  480. <div id="news<?=$NewsID?>" class="box news_post">
  481. <div class="head">
  482. <strong><?=Text::full_format($Title)?></strong> <?=time_diff($NewsTime);?>
  483. <? if (check_perms('admin_manage_news')) { ?>
  484. - <a href="tools.php?action=editnews&amp;id=<?=$NewsID?>" class="brackets">Edit</a>
  485. <? } ?>
  486. <span class="float_right"><a data-toggle-target="#newsbody<?=$NewsID?>" data-toggle-replace="Show" class="brackets">Hide</a></span>
  487. </div>
  488. <div id="newsbody<?=$NewsID?>" class="pad"><?=Text::full_format($Body)?></div>
  489. </div>
  490. <?
  491. if (++$Count > ($NewsCount - 1)) {
  492. break;
  493. }
  494. }
  495. ?>
  496. <div id="more_news" class="box">
  497. <div class="head">
  498. <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>
  499. </div>
  500. </div>
  501. </div>
  502. </div>
  503. <?
  504. View::show_footer(array('disclaimer'=>true));
  505. function contest() {
  506. global $DB, $Cache, $LoggedUser;
  507. list($Contest, $TotalPoints) = $Cache->get_value('contest');
  508. if (!$Contest) {
  509. $DB->query("
  510. SELECT
  511. UserID,
  512. SUM(Points),
  513. Username
  514. FROM users_points AS up
  515. JOIN users_main AS um ON um.ID = up.UserID
  516. GROUP BY UserID
  517. ORDER BY SUM(Points) DESC
  518. LIMIT 20");
  519. $Contest = $DB->to_array();
  520. $DB->query("
  521. SELECT SUM(Points)
  522. FROM users_points");
  523. list($TotalPoints) = $DB->next_record();
  524. $Cache->cache_value('contest', array($Contest, $TotalPoints), 600);
  525. }
  526. ?>
  527. <!-- Contest Section -->
  528. <div class="box box_contest">
  529. <div class="head colhead_dark"><strong>Quality time scoreboard</strong></div>
  530. <div class="pad">
  531. <ol style="padding-left: 5px;">
  532. <?
  533. foreach ($Contest as $User) {
  534. list($UserID, $Points, $Username) = $User;
  535. ?>
  536. <li><?=Users::format_username($UserID, false, false, false)?> (<?=number_format($Points)?>)</li>
  537. <? } ?>
  538. </ol>
  539. Total uploads: <?=$TotalPoints?><br />
  540. <a href="index.php?action=scoreboard">Full scoreboard</a>
  541. </div>
  542. </div>
  543. <!-- END contest Section -->
  544. <?
  545. } // contest()
  546. ?>