Contributing back some bug fixes
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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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. ThreadID,
  11. Time
  12. FROM news
  13. ORDER BY Time DESC
  14. LIMIT $NewsCount");
  15. $News = $DB->to_array(false, MYSQLI_NUM, false);
  16. $Cache->cache_value('news', $News, 3600 * 24 * 30);
  17. $Cache->cache_value('news_latest_id', $News[0][0], 0);
  18. $Cache->cache_value('news_latest_title', $News[0][1], 0);
  19. }
  20. if ($LoggedUser['LastReadNews'] != $News[0][0] && count($News[0][0]) > 0) {
  21. $Cache->begin_transaction("user_info_heavy_$UserID");
  22. $Cache->update_row(false, array('LastReadNews' => $News[0][0]));
  23. $Cache->commit_transaction(0);
  24. $DB->query("
  25. UPDATE users_info
  26. SET LastReadNews = '".$News[0][0]."'
  27. WHERE UserID = $UserID");
  28. $LoggedUser['LastReadNews'] = $News[0][0];
  29. }
  30. View::show_header('News', 'bbcode,news_ajax');
  31. ?>
  32. <div class="thin">
  33. <div class="sidebar">
  34. <?
  35. if (check_perms('users_mod')) {
  36. ?>
  37. <div class="box">
  38. <div class="head colhead_dark">
  39. <strong><a href="staffblog.php">Latest staff blog posts</a></strong>
  40. </div>
  41. <?
  42. if (($Blog = $Cache->get_value('staff_blog')) === false) {
  43. $DB->query("
  44. SELECT
  45. b.ID,
  46. um.Username,
  47. b.Title,
  48. b.Body,
  49. b.Time
  50. FROM staff_blog AS b
  51. LEFT JOIN users_main AS um ON b.UserID = um.ID
  52. ORDER BY Time DESC");
  53. $Blog = $DB->to_array(false, MYSQLI_NUM);
  54. $Cache->cache_value('staff_blog', $Blog, 1209600);
  55. }
  56. if (($SBlogReadTime = $Cache->get_value('staff_blog_read_'.$LoggedUser['ID'])) === false) {
  57. $DB->query("
  58. SELECT Time
  59. FROM staff_blog_visits
  60. WHERE UserID = ".$LoggedUser['ID']);
  61. if (list($SBlogReadTime) = $DB->next_record()) {
  62. $SBlogReadTime = strtotime($SBlogReadTime);
  63. } else {
  64. $SBlogReadTime = 0;
  65. }
  66. $Cache->cache_value('staff_blog_read_'.$LoggedUser['ID'], $SBlogReadTime, 1209600);
  67. }
  68. ?>
  69. <ul class="stats nobullet">
  70. <?
  71. $End = min(count($Blog), 5);
  72. for ($i = 0; $i < $End; $i++) {
  73. list($BlogID, $Author, $Title, $Body, $BlogTime) = $Blog[$i];
  74. $BlogTime = strtotime($BlogTime);
  75. ?>
  76. <li>
  77. <?=$SBlogReadTime < $BlogTime ? '<strong>' : ''?><?=($i + 1)?>.
  78. <a href="staffblog.php#blog<?=$BlogID?>"><?=$Title?></a>
  79. <?=$SBlogReadTime < $BlogTime ? '</strong>' : ''?>
  80. </li>
  81. <?
  82. }
  83. ?>
  84. </ul>
  85. </div>
  86. <? } ?>
  87. <div class="box">
  88. <div class="head colhead_dark"><strong><a href="blog.php">Latest blog posts</a></strong></div>
  89. <?
  90. if (($Blog = $Cache->get_value('blog')) === false) {
  91. $DB->query("
  92. SELECT
  93. b.ID,
  94. um.Username,
  95. b.UserID,
  96. b.Title,
  97. b.Body,
  98. b.Time,
  99. b.ThreadID
  100. FROM blog AS b
  101. LEFT JOIN users_main AS um ON b.UserID = um.ID
  102. ORDER BY Time DESC
  103. LIMIT 20");
  104. $Blog = $DB->to_array();
  105. $Cache->cache_value('blog', $Blog, 1209600);
  106. }
  107. ?>
  108. <ul class="stats nobullet">
  109. <?
  110. if (count($Blog) < 5) {
  111. $Limit = count($Blog);
  112. } else {
  113. $Limit = 5;
  114. }
  115. for ($i = 0; $i < $Limit; $i++) {
  116. list($BlogID, $Author, $AuthorID, $Title, $Body, $BlogTime, $ThreadID) = $Blog[$i];
  117. ?>
  118. <li>
  119. <?=($i + 1)?>. <a href="blog.php#blog<?=$BlogID?>"><?=$Title?></a>
  120. </li>
  121. <?
  122. }
  123. ?>
  124. </ul>
  125. </div>
  126. <?
  127. if (($Freeleeches = $Cache->get_value('shop_freeleech_list')) === false) {
  128. $DB->query("
  129. SELECT
  130. TorrentID,
  131. UNIX_TIMESTAMP(ExpiryTime),
  132. COALESCE(NULLIF(Name,''), NULLIF(NameRJ,''), NameJP) AS Name,
  133. WikiImage
  134. FROM shop_freeleeches AS sf
  135. LEFT JOIN torrents AS t on sf.TorrentID=t.ID
  136. LEFT JOIN torrents_group AS tg ON tg.ID=t.GroupID
  137. ORDER BY ExpiryTime ASC
  138. LIMIT 10");
  139. $Freeleeches = $DB->to_array();
  140. $Cache->cache_value('shop_freeleech_list', $Freeleeches, 1209600);
  141. }
  142. if (count($Freeleeches)) {
  143. ?>
  144. <div class="box">
  145. <div class="head colhead_dark"><strong><a href="torrents.php?freetorrent=1&order_by=seeders&order_way=asc">Freeleeches</a></strong></div>
  146. <ul class="stats nobullet">
  147. <?
  148. for ($i = 0; $i < count($Freeleeches); $i++) {
  149. list($ID, $ExpiryTime, $Name, $Image) = $Freeleeches[$i];
  150. if ($ExpiryTime < time()) { continue; }
  151. $DisplayTime = '('.str_replace(['year','month','week','day','hour','min','Just now','s',' '],['y','M','w','d','h','m','0m'],time_diff($ExpiryTime, 1, false)).') ';
  152. $DisplayName = '<a href="torrents.php?torrentid='.$ID.'"';
  153. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  154. $DisplayName .= " onmouseover=\"getCover(event)\" data-cover=\"".ImageTools::process($Image, 'thumb')."\" onmouseleave=\"ungetCover(event)\"";
  155. }
  156. $DisplayName .= '>'.$Name.'</a>';
  157. ?>
  158. <li>
  159. <strong class="fl_time"><?=$DisplayTime?></strong>
  160. <?=$DisplayName?>
  161. </li>
  162. <?
  163. }
  164. ?>
  165. </ul>
  166. </div>
  167. <?
  168. }
  169. ?>
  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. <?
  316. if (($TopicID = $Cache->get_value('polls_featured')) === false) {
  317. $DB->query("
  318. SELECT TopicID
  319. FROM forums_polls
  320. ORDER BY Featured DESC
  321. LIMIT 1");
  322. list($TopicID) = $DB->next_record();
  323. $Cache->cache_value('polls_featured', $TopicID, 0);
  324. }
  325. if ($TopicID) {
  326. if (($Poll = $Cache->get_value("polls_$TopicID")) === false) {
  327. $DB->query("
  328. SELECT Question, Answers, Featured, Closed
  329. FROM forums_polls
  330. WHERE TopicID = '$TopicID'");
  331. list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
  332. $Answers = unserialize($Answers);
  333. $DB->query("
  334. SELECT Vote, COUNT(UserID)
  335. FROM forums_polls_votes
  336. WHERE TopicID = '$TopicID'
  337. AND Vote != '0'
  338. GROUP BY Vote");
  339. $VoteArray = $DB->to_array(false, MYSQLI_NUM);
  340. $Votes = [];
  341. foreach ($VoteArray as $VoteSet) {
  342. list($Key,$Value) = $VoteSet;
  343. $Votes[$Key] = $Value;
  344. }
  345. for ($i = 1, $il = count($Answers); $i <= $il; ++$i) {
  346. if (!isset($Votes[$i])) {
  347. $Votes[$i] = 0;
  348. }
  349. }
  350. $Cache->cache_value("polls_$TopicID", array($Question, $Answers, $Votes, $Featured, $Closed), 0);
  351. } else {
  352. list($Question, $Answers, $Votes, $Featured, $Closed) = $Poll;
  353. }
  354. if (!empty($Votes)) {
  355. $TotalVotes = array_sum($Votes);
  356. $MaxVotes = max($Votes);
  357. } else {
  358. $TotalVotes = 0;
  359. $MaxVotes = 0;
  360. }
  361. $DB->query("
  362. SELECT Vote
  363. FROM forums_polls_votes
  364. WHERE UserID = '".$LoggedUser['ID']."'
  365. AND TopicID = '$TopicID'");
  366. list($UserResponse) = $DB->next_record();
  367. ?>
  368. <div class="box">
  369. <div class="head colhead_dark"><strong>Poll<? if ($Closed) { echo ' [Closed]'; } ?></strong></div>
  370. <div class="pad">
  371. <p><strong><?=display_str($Question)?></strong></p>
  372. <? if ($UserResponse !== null || $Closed) { ?>
  373. <ul class="poll nobullet">
  374. <? foreach ($Answers as $i => $Answer) {
  375. if ($TotalVotes > 0) {
  376. $Ratio = $Votes[$i] / $MaxVotes;
  377. $Percent = $Votes[$i] / $TotalVotes;
  378. } else {
  379. $Ratio = 0;
  380. $Percent = 0;
  381. }
  382. ?> <li<?=((!empty($UserResponse) && ($UserResponse == $i))?' class="poll_your_answer"':'')?>><?=display_str($Answers[$i])?> (<?=number_format($Percent * 100, 2)?>%)</li>
  383. <li class="graph">
  384. <span class="center_poll" style="width: <?=round($Ratio * 140)?>px;"></span>
  385. <br />
  386. </li>
  387. <? } ?>
  388. </ul>
  389. <strong>Votes:</strong> <?=number_format($TotalVotes)?><br />
  390. <? } else { ?>
  391. <div id="poll_container">
  392. <form class="vote_form" name="poll" id="poll" action="">
  393. <input type="hidden" name="action" value="poll" />
  394. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  395. <input type="hidden" name="topicid" value="<?=$TopicID?>" />
  396. <? foreach ($Answers as $i => $Answer) { ?>
  397. <input type="radio" name="vote" id="answer_<?=$i?>" value="<?=$i?>" />
  398. <label for="answer_<?=$i?>"><?=display_str($Answers[$i])?></label><br />
  399. <? } ?>
  400. <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 />
  401. <input type="button" onclick="ajax.post('index.php', 'poll', function(response) { $('#poll_container').raw().innerHTML = response } );" value="Vote" />
  402. </form>
  403. </div>
  404. <? } ?>
  405. <br /><strong>Topic:</strong> <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>">Visit</a>
  406. </div>
  407. </div>
  408. <?
  409. }
  410. //polls();
  411. ?>
  412. </div>
  413. <div class="main_column">
  414. <?
  415. $Recommend = $Cache->get_value('recommend');
  416. $Recommend_artists = $Cache->get_value('recommend_artists');
  417. if (!is_array($Recommend) || !is_array($Recommend_artists)) {
  418. $DB->query("
  419. SELECT
  420. tr.GroupID,
  421. tr.UserID,
  422. u.Username,
  423. tg.Name,
  424. tg.TagList
  425. FROM torrents_recommended AS tr
  426. JOIN torrents_group AS tg ON tg.ID = tr.GroupID
  427. LEFT JOIN users_main AS u ON u.ID = tr.UserID
  428. ORDER BY tr.Time DESC
  429. LIMIT 10");
  430. $Recommend = $DB->to_array();
  431. $Cache->cache_value('recommend', $Recommend, 1209600);
  432. $Recommend_artists = Artists::get_artists($DB->collect('GroupID'));
  433. $Cache->cache_value('recommend_artists', $Recommend_artists, 1209600);
  434. }
  435. if (count($Recommend) >= 4) {
  436. $Cache->increment('usage_index');
  437. ?>
  438. <div class="box" id="recommended">
  439. <div class="head colhead_dark">
  440. <strong>Latest Vanity House additions</strong>
  441. <a data-toggle-target="#vanityhouse", data-toggle-replace="Hide" class="brackets">Show</a>
  442. </div>
  443. <table class="torrent_table hidden" id="vanityhouse">
  444. <?
  445. foreach ($Recommend as $Recommendations) {
  446. list($GroupID, $UserID, $Username, $GroupName, $TagList) = $Recommendations;
  447. $TagsStr = '';
  448. if ($TagList) {
  449. // No vanity.house tag.
  450. $Tags = explode(' ', str_replace('_', '.', $TagList));
  451. $TagLinks = [];
  452. foreach ($Tags as $Tag) {
  453. if ($Tag == 'vanity.house') {
  454. continue;
  455. }
  456. $TagLinks[] = "<a href=\"torrents.php?action=basic&amp;taglist=$Tag\">$Tag</a> ";
  457. }
  458. $TagStr = "<br />\n<div class=\"tags\">".implode(', ', $TagLinks).'</div>';
  459. }
  460. ?>
  461. <tr>
  462. <td>
  463. <?=Artists::display_artists($Recommend_artists[$GroupID]) ?>
  464. <a href="torrents.php?id=<?=$GroupID?>"><?=$GroupName?></a> (by <?=Users::format_username($UserID, false, false, false)?>)
  465. <?=$TagStr?>
  466. </td>
  467. </tr>
  468. <? } ?>
  469. </table>
  470. </div>
  471. <!-- END recommendations section -->
  472. <?
  473. }
  474. $Count = 0;
  475. foreach ($News as $NewsItem) {
  476. list($NewsID, $Title, $Body, $ThreadID, $NewsTime) = $NewsItem;
  477. if (strtotime($NewsTime) > time()) {
  478. continue;
  479. }
  480. ?>
  481. <div id="news<?=$NewsID?>" class="box news_post">
  482. <div class="head">
  483. <strong><?=Text::full_format($Title)?></strong> <?=time_diff($NewsTime);?>
  484. <? if (check_perms('admin_manage_news')) { ?>
  485. - <a href="tools.php?action=editnews&amp;id=<?=$NewsID?>" class="brackets">Edit</a>
  486. <? } ?>
  487. <span class="float_right"><a data-toggle-target="#newsbody<?=$NewsID?>" data-toggle-replace="Show" class="brackets">Hide</a></span>
  488. </div>
  489. <div id="newsbody<?=$NewsID?>" class="pad">
  490. <?=Text::full_format($Body)?>
  491. <div class="news_link_to_forum"><a href="forums.php?action=viewthread&amp;threadid=<?=$ThreadID?>">Discuss this post in the forums</a></div>
  492. </div>
  493. </div>
  494. <?
  495. if (++$Count > ($NewsCount - 1)) {
  496. break;
  497. }
  498. }
  499. ?>
  500. <div id="more_news" class="box">
  501. <div class="head">
  502. <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>
  503. </div>
  504. </div>
  505. </div>
  506. </div>
  507. <?
  508. View::show_footer(array('disclaimer'=>true));
  509. function contest() {
  510. global $DB, $Cache, $LoggedUser;
  511. list($Contest, $TotalPoints) = $Cache->get_value('contest');
  512. if (!$Contest) {
  513. $DB->query("
  514. SELECT
  515. UserID,
  516. SUM(Points),
  517. Username
  518. FROM users_points AS up
  519. JOIN users_main AS um ON um.ID = up.UserID
  520. GROUP BY UserID
  521. ORDER BY SUM(Points) DESC
  522. LIMIT 20");
  523. $Contest = $DB->to_array();
  524. $DB->query("
  525. SELECT SUM(Points)
  526. FROM users_points");
  527. list($TotalPoints) = $DB->next_record();
  528. $Cache->cache_value('contest', array($Contest, $TotalPoints), 600);
  529. }
  530. ?>
  531. <!-- Contest Section -->
  532. <div class="box box_contest">
  533. <div class="head colhead_dark"><strong>Quality time scoreboard</strong></div>
  534. <div class="pad">
  535. <ol style="padding-left: 5px;">
  536. <?
  537. foreach ($Contest as $User) {
  538. list($UserID, $Points, $Username) = $User;
  539. ?>
  540. <li><?=Users::format_username($UserID, false, false, false)?> (<?=number_format($Points)?>)</li>
  541. <? } ?>
  542. </ol>
  543. Total uploads: <?=$TotalPoints?><br />
  544. <a href="index.php?action=scoreboard">Full scoreboard</a>
  545. </div>
  546. </div>
  547. <!-- END contest Section -->
  548. <?
  549. } // contest()
  550. ?>