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.

contest.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?
  2. if (!($ContestSettings = $Cache->get_value("contest_settings"))) {
  3. $DB->query("
  4. SELECT
  5. First,
  6. Second
  7. FROM misc
  8. WHERE
  9. Name='ContestRules'
  10. OR Name='ContestTimes'
  11. OR Name='ContestRewards'");
  12. if ($DB->has_results()) {
  13. list($QueryPart, $Rules) = $DB->next_record();
  14. list($StartTime, $EndTime) = $DB->next_record();
  15. list($Amount, $Currency) = $DB->next_record();
  16. }
  17. $ContestSettings = array(
  18. 'query' => html_entity_decode($QueryPart ?? '1=2', ENT_QUOTES),
  19. 'rules' => $Rules,
  20. 'start' => $StartTime ?? 0,
  21. 'end' => $EndTime ?? 0,
  22. 'reward' => ($Amount.' '.$Currency.'/torrent')
  23. );
  24. $Cache->cache_value('contest_settings', $ContestSettings);
  25. }
  26. if (!($Scores = $Cache->get_value("contest_scores"))) {
  27. $DB->query("
  28. SELECT
  29. u.Username,
  30. u.ID,
  31. COUNT(DISTINCT tg.ID) AS Uploads
  32. FROM torrents AS t
  33. LEFT JOIN torrents_group AS tg ON t.groupID=tg.ID
  34. LEFT JOIN users_main AS u ON t.UserID=u.ID
  35. WHERE
  36. $ContestSettings[query]
  37. AND UNIX_TIMESTAMP(t.Time) > $ContestSettings[start]
  38. AND UNIX_TIMESTAMP(t.Time) < $ContestSettings[end]
  39. GROUP BY UserID
  40. ORDER BY Uploads DESC
  41. LIMIT 50");
  42. $Scores = $DB->to_array();
  43. $Cache->cache_value('contest_scores', $Scores);
  44. }
  45. View::show_header('Contest');
  46. if (!$ContestSettings['start'] || !$ContestSettings['end']) {
  47. print '<h2>No Contests</h2>';
  48. } else {
  49. if (time() < $ContestSettings['start']) {
  50. print '<h2>Future Contest (Starts in '.time_diff($ContestSettings['start'],2,false).')</h2>';
  51. } else if (time() > $ContestSettings['end']) {
  52. print '<h2>Finished Contest</h2>';
  53. } else {
  54. print '<h2>Ongoing Contest! ('.time_diff($ContestSettings['end'],2,false).' remaining)</h2>';
  55. }
  56. ?>
  57. <div class="thin flex">
  58. <div class="box pad grow">
  59. <? if ($Scores) { ?>
  60. <h2 id="general">Scoreboard</h2>
  61. <table width="100%" class="contest_scoreboard">
  62. <tr class="colhead">
  63. <td>Place</td>
  64. <td>User</td>
  65. <td>Score</td>
  66. </tr>
  67. <? foreach ($Scores as $Place => $Score) { ?>
  68. <tr class="row">
  69. <td><?=($Place+1)?></td>
  70. <td><a href="/user.php?id=<?=$Score['ID']?>"><?=$Score['Username']?></a></td>
  71. <td><?=$Score['Uploads']?></td>
  72. </tr>
  73. <? } ?>
  74. </table>
  75. <? } else { ?>
  76. <h2>No Scores Yet</h2>
  77. <? } ?>
  78. </div>
  79. <div class="shrink flex" style="margin-left: 1em; flex-direction: column;">
  80. <div class="box pad">
  81. <h2>Qualifications</h2>
  82. <ul>
  83. <?
  84. print '<li>'.str_replace('\n', '</li><li>', $ContestSettings['rules']).'</li>'
  85. ?>
  86. </ul>
  87. </div>
  88. <div class="box pad">
  89. <h2>Rewards</h2>
  90. <ul>
  91. <li><?=$ContestSettings['reward']?></li>
  92. </ul>
  93. </div>
  94. </div>
  95. </div>
  96. <? }
  97. View::show_footer(); ?>