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 19KB

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