index.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. <?php
  2. $blogs = DB::selectAll("select blogs.id, title, poster, post_time from important_blogs, blogs where is_hidden = 0 and important_blogs.blog_id = blogs.id order by level desc, important_blogs.blog_id desc limit 8");
  3. $activateusers = DB::selectAll("select submitter, count(*) as cnt from submissions where datediff(now(), submit_time) <= 30 group by submitter order by cnt desc limit 12;");
  4. $topusers = DB::selectAll("select u.username, u.rating, u.rating_rd, u.rating_vol, u.motto, u.qq, count(*) cnt from user_info u inner join contests_registrants c on u.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc limit 12;");
  5. $hotusers = DB::selectAll("select username, rating, rating_rd, rating_vol, qq, motto from user_info order by rating_vol desc, username asc limit 12;");
  6. $topblogs = DB::selectAll("select id from blogs where is_hidden = false and zan >= 10 order by zan desc limit 10;");
  7. $recentblogs = DB::selectAll("select id from blogs where is_hidden = false and zan < 10 order by post_time desc limit 10;");
  8. $songs_data = htmlspecialchars(json_encode(DB::selectAll("select * from songs;")), ENT_QUOTES, 'UTF-8');
  9. // 最近比赛:未结束的按开始时间升序取,不足 5 场时补最近结束的
  10. $recent_contests = array();
  11. $result = DB::selectAll("select * from contests where status != 'finished' order by start_time asc, id asc limit 5");
  12. foreach ($result as $contest) {
  13. genMoreContestInfo($contest);
  14. $recent_contests[] = $contest;
  15. }
  16. if (count($recent_contests) < 5) {
  17. $need = 5 - count($recent_contests);
  18. $result = DB::selectAll("select * from contests where status = 'finished' order by start_time desc, id desc limit $need");
  19. foreach ($result as $contest) {
  20. genMoreContestInfo($contest);
  21. $recent_contests[] = $contest;
  22. }
  23. }
  24. // 随机用户背景图展示用
  25. $rand_users = [];
  26. $rand_users_raw = DB::selectAll("select username, bgurl, motto from user_info where bgurl is not null and bgurl != ''");
  27. foreach ($rand_users_raw as $u) {
  28. if (!preg_match('#^https?://#i', $u['bgurl'])) continue;
  29. $u_obj = queryUser($u['username']);
  30. if (!$u_obj) continue;
  31. $rand_users[] = [
  32. 'username' => $u['username'],
  33. 'href' => '/user/profile/' . urlencode($u['username']),
  34. 'bgurl' => $u['bgurl'],
  35. 'motto' => $u['motto'],
  36. 'userlink' => getUserLink($u['username']),
  37. 'avatar' => HTML::avatar_addr($u_obj, 128),
  38. ];
  39. }
  40. $rand_users_json = htmlspecialchars(json_encode($rand_users), ENT_QUOTES, 'UTF-8');
  41. ?>
  42. <?php echoUOJPageHeader(UOJConfig::$data['profile']['oj-name-short']) ?>
  43. <div id="songs-data" data-songs='<?php echo $songs_data; ?>'></div>
  44. <div class="row my-4 wyoj-topcard">
  45. <div class="card-body">
  46. <div class="row">
  47. <div class="col-sm-12 col-md-9">
  48. <table class="table table-sm">
  49. <tbody>
  50. <?php $now_cnt = 0; ?>
  51. <?php foreach ($blogs as $blog): ?>
  52. <?php
  53. $now_cnt++;
  54. $new_tag = '';
  55. if ((time() - strtotime($blog['post_time'])) / 3600 / 24 <= 7) {
  56. $new_tag = '<sup style="color:red">&nbsp;new</sup>';
  57. }
  58. ?>
  59. <tr>
  60. <td><a href="/blogs/<?= $blog['id'] ?>"><?= $blog['title'] ?></a><?= $new_tag ?></td>
  61. <td>by <?= getUserLink($blog['poster']) ?></td>
  62. <td><small><?= $blog['post_time'] ?></small></td>
  63. </tr>
  64. <?php endforeach ?>
  65. <?php for ($i = $now_cnt + 1; $i <= 8; $i++): ?>
  66. <tr><td colspan="233">&nbsp;</td></tr>
  67. <?php endfor ?>
  68. <tr><td class="text-right" colspan="233">
  69. <span>本歌曲由 </span><span id="recommender"></span><span> 推荐</span>
  70. </td></tr>
  71. <tr><td class="text-right" colspan="233">
  72. <a href="https://git.ryp.org.cn/wyoj/" class="text-info font-weight-bold">WyOJ 以及所有相关项目均为自由软件。</a>
  73. <a href="/announcements"><?= UOJLocale::get('all the announcements') ?></a>
  74. </td></tr>
  75. <tr>
  76. <td class="text-right" colspan="233">
  77. <span class="text-danger font-weight-bold">声明:本网站属个人非经营性网站,仅用于学习交流,无任何盈利目的,与任何组织无关</span>
  78. <a href="/certs-manage/songs">我要推歌</a>
  79. </td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. <div class="col-xs-6 col-sm-4 col-md-3">
  85. <div class="card" style="max-width:300px; width:100%; border-radius:0; ">
  86. <div class="image-frame" style="aspect-ratio:1/1; position:relative;">
  87. <img id="photo" src="" alt="" style="width:100%; height:100%; object-fit:cover; display:block; cursor:pointer; -webkit-tap-highlight-color:transparent;">
  88. </div>
  89. <div class="intro" style="padding:1.6rem 1.8rem 1.2rem; text-align:center; background:#ffffff;">
  90. <p id="name" style="font-size:1.0rem; font-weight:800; letter-spacing:1px; margin-bottom:0.5rem; line-height:1.2; margin-block:0;"></p>
  91. <p id="amb" style="font-size:0.7rem; font-weight:400; color:#4f5d69; margin-bottom:0.25rem; line-height:1.5; border-top:1px dashed #cdd9e3; padding-top:0.8rem; white-space:pre-wrap; margin-block:0;"></p>
  92. <p id="writer" style="font-size:0.7rem; font-weight:400; color:#4f5d69; margin-bottom:0.25rem; line-height:1.5; white-space:pre-wrap; margin-block:0;"></p>
  93. </div>
  94. <div class="button-wrapper" style="padding:0.2rem 1.8rem 2rem 1.8rem; background:#ffffff;">
  95. <style>
  96. #randomBtn{
  97. display: inline-flex;
  98. align-items: center;
  99. justify-content: center;
  100. gap: 0.6rem;
  101. width: 100%;
  102. background: #1f2f3b;
  103. color: white;
  104. padding: 0.7rem 0;
  105. cursor: pointer;
  106. transition: all 0.2s ease;
  107. letter-spacing: 0.5px;
  108. border: 1px solid rgba(255, 255, 255, 0.2);
  109. backdrop-filter: blur(4px);
  110. font-family: inherit;
  111. line-height: 1;
  112. }
  113. </style>
  114. <button id="randomBtn">换一首</button>
  115. </div>
  116. </div>
  117. <script>
  118. (function() {
  119. let dataDiv = document.getElementById('songs-data');
  120. let library = JSON.parse(dataDiv.dataset.songs);
  121. const photoImg = document.getElementById('photo');
  122. const nameEl = document.getElementById('name');
  123. const ambEl = document.getElementById('amb');
  124. const writerEl = document.getElementById('writer');
  125. const randomBtn = document.getElementById('randomBtn');
  126. const recommenderEl = document.getElementById('recommender');
  127. let lastIndex = -1;
  128. let currentMusicLink = library[0].musiclink;
  129. photoImg.addEventListener('mousedown', function(e) {
  130. this.style.opacity = '0.8';
  131. });
  132. photoImg.addEventListener('mouseup', function(e) {
  133. this.style.opacity = '';
  134. });
  135. photoImg.addEventListener('mouseleave', function(e) {
  136. this.style.opacity = '';
  137. });
  138. photoImg.addEventListener('touchstart', function(e) {
  139. this.style.opacity = '0.8';
  140. });
  141. photoImg.addEventListener('touchend', function(e) {
  142. this.style.opacity = '';
  143. });
  144. photoImg.addEventListener('touchcancel', function(e) {
  145. this.style.opacity = '';
  146. });
  147. function setBtnActive() {
  148. randomBtn.style.background = '#17242e';
  149. randomBtn.style.transform = 'scale(0.98)';
  150. randomBtn.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
  151. }
  152. function setBtnNormal() {
  153. randomBtn.style.background = '#1f2f3b';
  154. randomBtn.style.transform = 'scale(1)';
  155. randomBtn.style.boxShadow = 'none';
  156. }
  157. randomBtn.addEventListener('mousedown', setBtnActive);
  158. randomBtn.addEventListener('mouseup', setBtnNormal);
  159. randomBtn.addEventListener('mouseleave', setBtnNormal);
  160. randomBtn.addEventListener('touchstart', setBtnActive);
  161. randomBtn.addEventListener('touchend', setBtnNormal);
  162. randomBtn.addEventListener('touchcancel', setBtnNormal);
  163. photoImg.addEventListener('click', function() {
  164. if (currentMusicLink) {
  165. window.open(currentMusicLink, '_blank');
  166. }
  167. });
  168. function randmusic() {
  169. let randid = lastIndex;
  170. while (randid === lastIndex) {
  171. randid = Math.floor(Math.random() * library.length);
  172. }
  173. if (lastIndex == -1) randid = 3;
  174. lastIndex = randid;
  175. const ys = library[randid];
  176. photoImg.src = ys.cover;
  177. photoImg.alt = ys.name;
  178. nameEl.textContent = ys.name;
  179. ambEl.textContent = ys.album;
  180. writerEl.textContent = ys.writer;
  181. recommenderEl.textContent = ys.user;
  182. currentMusicLink = ys.click;
  183. }
  184. randmusic();
  185. randomBtn.addEventListener('click', function() {
  186. randmusic();
  187. });
  188. })();
  189. </script>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. <?php
  195. // ---- 日期 ----
  196. $todayTs = time();
  197. $dayNum = (int)date('j', $todayTs);
  198. $monthNum = (int)date('n', $todayTs);
  199. $wday = (int)date('w', $todayTs);
  200. $monthCN = ['一','二','三','四','五','六','七','八','九','十','十一','十二'];
  201. $weekCN = ['日','一','二','三','四','五','六'];
  202. $bigMonths = [1,3,5,7,8,10,12];
  203. if ($monthNum == 2) {
  204. $sizeChar = '平'; // 闰年可改成 '闰'
  205. } elseif (in_array($monthNum, $bigMonths)) {
  206. $sizeChar = '大';
  207. } else {
  208. $sizeChar = '小';
  209. }
  210. $monthText = $monthCN[$monthNum - 1] . '月' . $sizeChar;
  211. $weekText = '星期' . $weekCN[$wday];
  212. $todayMidnight = strtotime(date('Y-m-d', $todayTs));
  213. $noipTs = strtotime('2026-11-28');
  214. $daysLeft = max(0, (int)floor(($noipTs - $todayMidnight) / 86400));
  215. $csp1Ts = strtotime('2026-09-19');
  216. $csp1daysLeft = max(0, (int)floor(($csp1Ts - $todayMidnight) / 86400));
  217. $csp2Ts = strtotime('2026-10-31');
  218. $csp2daysLeft = max(0, (int)floor(($csp2Ts - $todayMidnight) / 86400));
  219. $gk27Ts = strtotime('2027-06-07');
  220. $gk27daysLeft = max(0, (int)floor(($gk27Ts - $todayMidnight) / 86400));
  221. $gk28Ts = strtotime('2028-06-07');
  222. $gk28daysLeft = max(0, (int)floor(($gk28Ts - $todayMidnight) / 86400));
  223. ?>
  224. <div class="row my-4">
  225. <!-- ============ 左列:日程 + 博客 ============ -->
  226. <div class="col-12 col-lg-9">
  227. <!-- 黑色日期卡片 -->
  228. <div class="mb-4 wyoj-date-card" id="wyoj-date-card"
  229. style="position:relative;overflow:hidden;background:#000;color:#fff;padding:2rem 1.5rem;border-radius:0;text-shadow:0 1px 3px rgba(0,0,0,0.75);">
  230. <!-- 随机方格背景:canvas -->
  231. <canvas id="wyoj-date-canvas"
  232. style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:0;pointer-events:none;"></canvas>
  233. <!-- 内容层 -->
  234. <div style="position:relative;z-index:1;">
  235. <div class="d-flex justify-content-center align-items-center">
  236. <div style="writing-mode:vertical-rl;font-size:1.5rem;font-weight:bold;letter-spacing:0.3em;line-height:1;">
  237. <?= $monthText ?>
  238. </div>
  239. <div class="mx-4" style="font-size:5rem;font-weight:600;line-height:1;">
  240. <?= $dayNum ?>
  241. </div>
  242. <div style="writing-mode:vertical-rl;font-size:1.5rem;font-weight:bold;letter-spacing:0.3em;line-height:1;">
  243. <?= $weekText ?>
  244. </div>
  245. </div>
  246. <div class="text-center mt-4" style="font-size:1rem;letter-spacing:0.05em;">
  247. <?php if ($daysLeft > 0): ?>
  248. 距 <strong>NOIP2026</strong> 还有 <strong><?= $daysLeft ?></strong> 天
  249. <?php elseif ($daysLeft === 0): ?>
  250. <strong>NOIP2026</strong> 就是今天
  251. <?php else: ?>
  252. <strong>NOIP2026</strong> 已结束
  253. <?php endif; ?>
  254. <br/>
  255. <?php if ($csp1daysLeft > 0): ?>
  256. 距 <strong>CSP-J/S 2026 第一轮</strong> 还有 <strong><?= $csp1daysLeft ?></strong> 天
  257. <?php elseif ($csp1daysLeft === 0): ?>
  258. <strong>CSP-J/S 2026 第一轮</strong> 就是今天
  259. <?php else: ?>
  260. <strong>CSP-J/S 2026 第一轮</strong> 已结束
  261. <?php endif; ?>
  262. <br/>
  263. <?php if ($csp2daysLeft > 0): ?>
  264. 距 <strong>CSP-J/S 2026 第二轮</strong> 还有 <strong><?= $csp2daysLeft ?></strong> 天
  265. <?php elseif ($csp2daysLeft === 0): ?>
  266. <strong>CSP-J/S 2026 第二轮</strong> 就是今天!
  267. <?php else: ?>
  268. <strong>CSP-J/S 2026 第二轮</strong> 已结束
  269. <?php endif; ?>
  270. <br/>
  271. <?php if ($gk27daysLeft > 0): ?>
  272. 距 <strong>2027 年普通高等学校招生全国统一考试</strong> 还有 <strong><?= $gk27daysLeft ?></strong> 天
  273. <?php elseif ($gk27daysLeft === 0): ?>
  274. <strong>2027 年普通高等学校招生全国统一考试</strong> 就是今天!
  275. <?php else: ?>
  276. <strong>2027 年普通高等学校招生全国统一考试</strong> 已结束
  277. <?php endif; ?>
  278. <br/>
  279. <?php if ($gk28daysLeft > 0): ?>
  280. 距 <strong>2028 年普通高等学校招生全国统一考试</strong> 还有 <strong><?= $gk28daysLeft ?></strong> 天
  281. <?php elseif ($gk28daysLeft === 0): ?>
  282. <strong>2028 年普通高等学校招生全国统一考试</strong> 就是今天!
  283. <?php else: ?>
  284. <strong>2028 年普通高等学校招生全国统一考试</strong> 已结束
  285. <?php endif; ?>
  286. </div>
  287. </div>
  288. </div>
  289. <script>
  290. (function () {
  291. var card = document.getElementById('wyoj-date-card');
  292. var canvas = document.getElementById('wyoj-date-canvas');
  293. if (!card || !canvas) return;
  294. var ctx = canvas.getContext('2d');
  295. // ===== 可调参数 =====
  296. var COLORS = ['#000000', '#0c0c0c', '#181818', '#242424', '#303030'];
  297. var CELL = 26; // 每格边长(px)
  298. var P = 0.3; // 每格每轮变色概率(期望值)
  299. var PERIOD = 3000; // 刷新间隔(ms)
  300. var Z = 1.96; // 95% 置信区间
  301. var USE_DPR = false; // 是否按设备像素比放大 canvas(false 更省 CPU)
  302. // ====================
  303. var dpr = USE_DPR ? (window.devicePixelRatio || 1) : 1;
  304. var cols = 0, rows = 0, nCells = 0;
  305. var lastW = 0, lastH = 0;
  306. var gridColors = [];
  307. var idx = null;
  308. var xs = null, ys = null;
  309. var rafId = null;
  310. var running = false;
  311. var lastTick = 0;
  312. function randColor() {
  313. return COLORS[(Math.random() * COLORS.length) | 0];
  314. }
  315. function computeBounds() {
  316. var w = card.clientWidth;
  317. var h = card.clientHeight;
  318. xs = new Int32Array(cols + 1);
  319. ys = new Int32Array(rows + 1);
  320. for (var i = 0; i <= cols; i++) xs[i] = Math.round(i * w / cols);
  321. for (var j = 0; j <= rows; j++) ys[j] = Math.round(j * h / rows);
  322. }
  323. function build() {
  324. var w = card.clientWidth;
  325. var h = card.clientHeight;
  326. if (w === 0 || h === 0) return;
  327. if (w === lastW && h === lastH) return; // 尺寸没变就不重建
  328. lastW = w; lastH = h;
  329. cols = Math.max(1, Math.ceil(w / CELL));
  330. rows = Math.max(1, Math.ceil(h / CELL));
  331. nCells = cols * rows;
  332. canvas.width = Math.round(w * dpr);
  333. canvas.height = Math.round(h * dpr);
  334. canvas.style.width = w + 'px';
  335. canvas.style.height = h + 'px';
  336. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  337. ctx.imageSmoothingEnabled = false;
  338. computeBounds();
  339. gridColors = [];
  340. for (var y = 0; y < rows; y++) {
  341. var row = [];
  342. for (var x = 0; x < cols; x++) row.push(randColor());
  343. gridColors.push(row);
  344. }
  345. idx = new Int32Array(nCells);
  346. for (var i = 0; i < nCells; i++) idx[i] = i;
  347. redrawAll();
  348. }
  349. function redrawAll() {
  350. for (var y = 0; y < rows; y++) {
  351. var y0 = ys[y], y1 = ys[y + 1];
  352. for (var x = 0; x < cols; x++) {
  353. ctx.fillStyle = gridColors[y][x];
  354. ctx.fillRect(xs[x], y0, xs[x + 1] - xs[x], y1 - y0);
  355. }
  356. }
  357. }
  358. function tick() {
  359. if (nCells === 0) return;
  360. var mu = nCells * P;
  361. var sigma = Math.sqrt(nCells * P * (1 - P));
  362. var lo = Math.max(0, Math.floor(mu - Z * sigma));
  363. var hi = Math.min(nCells, Math.ceil(mu + Z * sigma));
  364. var m = lo + Math.floor(Math.random() * (hi - lo + 1));
  365. for (var i = 0; i < m; i++) {
  366. var j = i + Math.floor(Math.random() * (nCells - i));
  367. var t = idx[i]; idx[i] = idx[j]; idx[j] = t;
  368. }
  369. for (var k = 0; k < m; k++) {
  370. var ci = idx[k];
  371. var x = ci % cols;
  372. var y = (ci / cols) | 0;
  373. var c = randColor();
  374. gridColors[y][x] = c;
  375. ctx.fillStyle = c;
  376. ctx.fillRect(xs[x], ys[y], xs[x + 1] - xs[x], ys[y + 1] - ys[y]);
  377. }
  378. }
  379. function loop(now) {
  380. rafId = null;
  381. if (now - lastTick >= PERIOD) {
  382. lastTick = now;
  383. tick();
  384. }
  385. if (running) rafId = requestAnimationFrame(loop);
  386. }
  387. function start() {
  388. if (running) return;
  389. running = true;
  390. lastTick = performance.now();
  391. rafId = requestAnimationFrame(loop);
  392. }
  393. function stop() {
  394. running = false;
  395. if (rafId) { cancelAnimationFrame(rafId); rafId = null; }
  396. }
  397. build();
  398. if (window.ResizeObserver) {
  399. new ResizeObserver(function () { build(); }).observe(card);
  400. } else {
  401. window.addEventListener('resize', build);
  402. }
  403. if (window.IntersectionObserver) {
  404. new IntersectionObserver(function (entries) {
  405. if (entries[0].isIntersecting) start(); else stop();
  406. }, { threshold: 0 }).observe(card);
  407. } else {
  408. start();
  409. }
  410. document.addEventListener('visibilitychange', function () {
  411. if (document.hidden) stop(); else start();
  412. });
  413. })();
  414. </script>
  415. <?php if (!empty($rand_users)): ?>
  416. <div class="mb-4" id="wyoj-random-user-wrap">
  417. <div class="wyoj-random-user" id="wyoj-random-user-link">
  418. <div class="wyoj-random-img-wrap">
  419. <img class="wyoj-rand-img" id="wyoj-rand-img-a" src="" alt="">
  420. <img class="wyoj-rand-img" id="wyoj-rand-img-b" src="" alt="">
  421. <button type="button" class="wyoj-rand-arrow wyoj-rand-arrow-left"
  422. id="wyoj-rand-prev" aria-label="上一个">‹</button>
  423. <button type="button" class="wyoj-rand-arrow wyoj-rand-arrow-right"
  424. id="wyoj-rand-next" aria-label="下一个">›</button>
  425. <button type="button" class="wyoj-rand-pin pinned"
  426. id="wyoj-rand-pin" aria-label="固定" title="已固定,点击恢复自动切换">📌</button>
  427. </div>
  428. <div class="wyoj-random-info">
  429. <span class="wyoj-rand-motto" id="wyoj-rand-motto"></span>
  430. <span class="wyoj-rand-userlink" id="wyoj-rand-userlink"></span>
  431. <img class="wyoj-rand-avatar" id="wyoj-rand-avatar" src="" alt="">
  432. </div>
  433. </div>
  434. <div id="wyoj-random-user-data" data-users='<?= $rand_users_json ?>' style="display:none;"></div>
  435. </div>
  436. <script>
  437. (function () {
  438. var wrap = document.getElementById('wyoj-random-user-wrap');
  439. if (!wrap) return;
  440. var dataEl = document.getElementById('wyoj-random-user-data');
  441. if (!dataEl) return;
  442. var users;
  443. try { users = JSON.parse(dataEl.dataset.users); } catch (e) { wrap.style.display = 'none'; return; }
  444. if (!users || users.length === 0) { wrap.style.display = 'none'; return; }
  445. var link = document.getElementById('wyoj-random-user-link');
  446. var imgA = document.getElementById('wyoj-rand-img-a');
  447. var imgB = document.getElementById('wyoj-rand-img-b');
  448. var mottoEl = document.getElementById('wyoj-rand-motto');
  449. var userEl = document.getElementById('wyoj-rand-userlink');
  450. var avatarEl = document.getElementById('wyoj-rand-avatar');
  451. var prevBtn = document.getElementById('wyoj-rand-prev');
  452. var nextBtn = document.getElementById('wyoj-rand-next');
  453. var pinBtn = document.getElementById('wyoj-rand-pin');
  454. var frontImg = imgA;
  455. var backImg = imgB;
  456. var currentIdx = -1;
  457. var currentUrl = '';
  458. var timer = null;
  459. var pinned = true;
  460. var SWAP_MS = 5000;
  461. function preload(url) {
  462. return new Promise(function (resolve, reject) {
  463. var im = new Image();
  464. im.onload = function () { resolve(); };
  465. im.onerror = function () { reject(); };
  466. im.src = url;
  467. });
  468. }
  469. function applyInfo(u) {
  470. mottoEl.textContent = u.motto || '';
  471. userEl.innerHTML = u.userlink;
  472. avatarEl.src = u.avatar;
  473. currentUrl = u.href;
  474. }
  475. function showImage(u) {
  476. backImg.src = u.bgurl;
  477. requestAnimationFrame(function () {
  478. backImg.classList.add('active');
  479. frontImg.classList.remove('active');
  480. var t = frontImg; frontImg = backImg; backImg = t;
  481. });
  482. }
  483. // 展示指定索引;如果图挂了就往同方向继续找
  484. function goTo(idx, dir, tries) {
  485. dir = dir || 1;
  486. tries = tries || 0;
  487. if (tries >= users.length) return;
  488. var realIdx = ((idx % users.length) + users.length) % users.length;
  489. var u = users[realIdx];
  490. preload(u.bgurl).then(function () {
  491. currentIdx = realIdx;
  492. applyInfo(u);
  493. showImage(u);
  494. }, function () {
  495. goTo(realIdx + dir, dir, tries + 1);
  496. });
  497. }
  498. function schedule() {
  499. clearTimeout(timer);
  500. timer = null;
  501. if (pinned) return;
  502. if (users.length <= 1) return;
  503. timer = setTimeout(function () {
  504. goTo(currentIdx + 1, 1, 0);
  505. schedule();
  506. }, SWAP_MS);
  507. }
  508. function pickRandom() {
  509. if (users.length === 1) return 0;
  510. var i = currentIdx;
  511. while (i === currentIdx) i = Math.floor(Math.random() * users.length);
  512. return i;
  513. }
  514. // 初始化
  515. (function init() {
  516. var tries = 0;
  517. var idx = -1;
  518. for (var i = 0; i < users.length; i++)
  519. if (users[i].username == 'ryp') { idx = i; break; }
  520. // 夹带私货了
  521. if (idx < 0) idx = Math.floor(Math.random() * users.length);
  522. function attempt() {
  523. if (tries >= users.length) { wrap.style.display = 'none'; return; }
  524. tries++;
  525. var u = users[idx];
  526. preload(u.bgurl).then(function () {
  527. currentIdx = idx;
  528. frontImg.src = u.bgurl;
  529. frontImg.classList.add('active');
  530. applyInfo(u);
  531. schedule();
  532. }, function () {
  533. idx = (idx + 1) % users.length;
  534. attempt();
  535. });
  536. }
  537. attempt();
  538. })();
  539. // 点击卡片主体(非按钮、非内部链接)跳转
  540. link.addEventListener('click', function (e) {
  541. if (e.target.closest('button')) return;
  542. if (e.target.closest('a')) return;
  543. if (currentUrl) window.location.href = currentUrl;
  544. });
  545. // 上一个
  546. prevBtn.addEventListener('click', function (e) {
  547. e.stopPropagation();
  548. e.preventDefault();
  549. goTo(currentIdx - 1, -1, 0);
  550. schedule();
  551. });
  552. // 下一个
  553. nextBtn.addEventListener('click', function (e) {
  554. e.stopPropagation();
  555. e.preventDefault();
  556. goTo(currentIdx + 1, 1, 0);
  557. schedule();
  558. });
  559. // 固定 / 取消固定
  560. pinBtn.addEventListener('click', function (e) {
  561. e.stopPropagation();
  562. e.preventDefault();
  563. pinned = !pinned;
  564. pinBtn.classList.toggle('pinned', pinned);
  565. pinBtn.title = pinned ? '已固定,点击恢复自动切换' : '固定当前';
  566. if (pinned) {
  567. clearTimeout(timer);
  568. timer = null;
  569. } else {
  570. schedule();
  571. }
  572. });
  573. document.addEventListener('visibilitychange', function () {
  574. if (document.hidden) {
  575. clearTimeout(timer);
  576. timer = null;
  577. } else {
  578. schedule();
  579. }
  580. });
  581. })();
  582. </script>
  583. <?php endif ?>
  584. <!-- 博客列表 -->
  585. <div class="row">
  586. <?php foreach ($recentblogs as $blog): ?>
  587. <?= echoBlogCard(queryBlog($blog['id'])) ?>
  588. <?php endforeach ?>
  589. <?php foreach ($topblogs as $blog): ?>
  590. <?= echoBlogCard(queryBlog($blog['id'])) ?>
  591. <?php endforeach ?>
  592. </div>
  593. </div>
  594. <!-- ============ 右列:排行榜 ============ -->
  595. <div class="col-12 col-lg-3">
  596. <!-- 活跃 -->
  597. <div class="card shadow-sm border-0 mb-3">
  598. <div class="card-body p-3">
  599. <h6 class="font-weight-bold mb-3">活跃排行榜</h6>
  600. <?php foreach ($activateusers as $username): ?>
  601. <?php $user = queryUser($username['submitter']); ?>
  602. <div class="d-flex align-items-start border-bottom pb-2 mb-2">
  603. <img class="uoj-avatar rounded-circle flex-shrink-0 mr-2"
  604. style="width:36px;height:36px;object-fit:cover;"
  605. src="https://q.qlogo.cn/g?b=qq&nk=<?= $user['qq'] ?>&s=100" alt="...">
  606. <div class="flex-grow-1" style="min-width:0;">
  607. <div class="text-truncate font-weight-bold" style="font-size:0.9rem;">
  608. <?= getUserLink($user['username']) ?>
  609. </div>
  610. <div class="text-truncate" style="font-size:0.8rem;font-family:'SimSun','宋体','Songti SC','STSong',serif;">
  611. <?= $user['motto'] ?>
  612. </div>
  613. </div>
  614. </div>
  615. <?php endforeach ?>
  616. </div>
  617. </div>
  618. <!-- 比赛 -->
  619. <div class="card shadow-sm border-0 mb-3">
  620. <div class="card-body p-3">
  621. <h6 class="font-weight-bold mb-1">比赛排行榜</h6>
  622. <div class="mb-3" style="font-size:0.75rem;">
  623. <span class="text-muted">180 天内三场及以上</span>
  624. <a href="/ranklist" class="ml-1">全部排名</a>
  625. </div>
  626. <?php foreach ($topusers as $user): ?>
  627. <div class="d-flex align-items-start border-bottom pb-2 mb-2">
  628. <img class="uoj-avatar rounded-circle flex-shrink-0 mr-2"
  629. style="width:36px;height:36px;object-fit:cover;"
  630. src="https://q.qlogo.cn/g?b=qq&nk=<?= $user['qq'] ?>&s=100" alt="...">
  631. <div class="flex-grow-1" style="min-width:0;">
  632. <div class="d-flex justify-content-between align-items-baseline">
  633. <span class="text-truncate font-weight-bold" style="font-size:0.9rem;">
  634. <?= getUserLink($user['username']) ?>
  635. </span>
  636. <strong class="text-danger ml-1 flex-shrink-0" style="font-size:0.75rem;">
  637. <?= $user['rating'] ?> <small>(±<?= round($user['rating_rd']) * 2 ?>)</small>
  638. </strong>
  639. </div>
  640. <div class="text-truncate" style="font-size:0.8rem;font-family:'SimSun','宋体','Songti SC','STSong',serif;">
  641. <?= $user['motto'] ?>
  642. </div>
  643. </div>
  644. </div>
  645. <?php endforeach ?>
  646. </div>
  647. </div>
  648. <!-- 黑马 -->
  649. <div class="card shadow-sm border-0 mb-3">
  650. <div class="card-body p-3">
  651. <h6 class="font-weight-bold mb-3">黑马 / 爆冷榜</h6>
  652. <?php foreach ($hotusers as $user): ?>
  653. <div class="d-flex align-items-start border-bottom pb-2 mb-2">
  654. <img class="uoj-avatar rounded-circle flex-shrink-0 mr-2"
  655. style="width:36px;height:36px;object-fit:cover;"
  656. src="https://q.qlogo.cn/g?b=qq&nk=<?= $user['qq'] ?>&s=100" alt="...">
  657. <div class="flex-grow-1" style="min-width:0;">
  658. <div class="d-flex justify-content-between align-items-baseline">
  659. <span class="text-truncate font-weight-bold" style="font-size:0.9rem;">
  660. <?= getUserLink($user['username']) ?>
  661. </span>
  662. <strong class="text-danger ml-1 flex-shrink-0" style="font-size:0.75rem;">
  663. Vol <?= round(1000 * $user['rating_vol']) / 1000 ?>
  664. </strong>
  665. </div>
  666. <div class="text-truncate" style="font-size:0.8rem;font-family:'SimSun','宋体','Songti SC','STSong',serif;">
  667. <?= $user['motto'] ?>
  668. </div>
  669. </div>
  670. </div>
  671. <?php endforeach ?>
  672. </div>
  673. </div>
  674. </div>
  675. </div>
  676. <!-- 博客卡片悬停效果 -->
  677. <style>
  678. .wyoj-blog-card {
  679. transition: box-shadow .2s ease;
  680. }
  681. .wyoj-blog-card:hover {
  682. box-shadow: 0 4px 14px rgba(0,0,0,.10) !important;
  683. }
  684. .wyoj-blog-card .wyoj-blog-title {
  685. font-size: 1.05rem;
  686. line-height: 1.5;
  687. }
  688. /* ---------- 随机用户背景图卡片 ---------- */
  689. .wyoj-random-user {
  690. display: block;
  691. background: #fff;
  692. border: 0;
  693. border-radius: 0;
  694. overflow: hidden;
  695. color: inherit;
  696. box-shadow: 0 .125rem .25rem rgba(0,0,0,.075);
  697. transition: box-shadow 0.2s ease;
  698. cursor: pointer;
  699. }
  700. .wyoj-random-user:hover {
  701. box-shadow: 0 .25rem .75rem rgba(0,0,0,.10);
  702. }
  703. .wyoj-random-img-wrap {
  704. position: relative;
  705. aspect-ratio: 16 / 7;
  706. background: #f8f9fa;
  707. overflow: hidden;
  708. }
  709. .wyoj-rand-img {
  710. position: absolute;
  711. inset: 0;
  712. width: 100%;
  713. height: 100%;
  714. object-fit: cover;
  715. opacity: 0;
  716. transition: opacity 0.6s ease;
  717. }
  718. .wyoj-rand-img.active { opacity: 1; }
  719. /* 左右箭头 */
  720. .wyoj-rand-arrow {
  721. position: absolute;
  722. top: 50%;
  723. transform: translateY(-50%);
  724. width: 32px;
  725. height: 32px;
  726. border: 0;
  727. border-radius: 50%;
  728. background: rgba(255,255,255,0.85);
  729. color: #333;
  730. font-size: 20px;
  731. line-height: 1;
  732. padding: 0 0 2px 0;
  733. cursor: pointer;
  734. display: flex;
  735. align-items: center;
  736. justify-content: center;
  737. z-index: 3;
  738. opacity: 0.4;
  739. transition: opacity 0.2s ease, background 0.2s ease, transform 0.1s ease;
  740. -webkit-tap-highlight-color: transparent;
  741. }
  742. .wyoj-random-user:hover .wyoj-rand-arrow { opacity: 1; }
  743. .wyoj-rand-arrow:hover {
  744. background: #fff;
  745. transform: translateY(-50%) scale(1.08);
  746. }
  747. .wyoj-rand-arrow:active { transform: translateY(-50%) scale(0.96); }
  748. .wyoj-rand-arrow-left { left: 10px; }
  749. .wyoj-rand-arrow-right { right: 10px; }
  750. /* 固定按钮 */
  751. .wyoj-rand-pin {
  752. position: absolute;
  753. top: 10px;
  754. right: 10px;
  755. width: 28px;
  756. height: 28px;
  757. border: 0;
  758. border-radius: 50%;
  759. background: rgba(255,255,255,0.85);
  760. font-size: 13px;
  761. line-height: 1;
  762. padding: 0;
  763. cursor: pointer;
  764. display: flex;
  765. align-items: center;
  766. justify-content: center;
  767. z-index: 3;
  768. opacity: 0.4;
  769. transition: opacity 0.2s ease, background 0.2s ease, transform 0.1s ease;
  770. -webkit-tap-highlight-color: transparent;
  771. }
  772. .wyoj-random-user:hover .wyoj-rand-pin { opacity: 1; }
  773. .wyoj-rand-pin:hover { background: #fff; }
  774. .wyoj-rand-pin:active { transform: scale(0.94); }
  775. .wyoj-rand-pin.pinned {
  776. opacity: 1;
  777. background: #ffc107;
  778. }
  779. .wyoj-rand-pin.pinned:hover { background: #ffb300; }
  780. /* 信息行 */
  781. .wyoj-random-info {
  782. padding: 12px 16px;
  783. display: flex;
  784. align-items: center;
  785. gap: 10px;
  786. min-width: 0;
  787. }
  788. .wyoj-rand-motto {
  789. color: #6c757d;
  790. font-size: 0.85rem;
  791. line-height: 1.4;
  792. overflow: hidden;
  793. text-overflow: ellipsis;
  794. white-space: nowrap;
  795. flex-shrink: 1;
  796. min-width: 0;
  797. }
  798. .wyoj-rand-userlink {
  799. font-size: 0.9rem;
  800. line-height: 1.3;
  801. flex-shrink: 0;
  802. white-space: nowrap;
  803. }
  804. .wyoj-rand-avatar {
  805. width: 24px;
  806. height: 24px;
  807. object-fit: cover;
  808. border-radius: 50%;
  809. border: 1px solid #dee2e6;
  810. flex-shrink: 0;
  811. margin-left: auto;
  812. }
  813. </style>
  814. <?php echoUOJPageFooter() ?>