) and the blog post page // (/blog//post/). // // Expects: // $owner blog owner's username // $show_write_buttons render the "写新博客 / 写新幻灯片" buttons (owner only) // $show_tags render the 标签 card (archive page only) // $all_tags tags for the 标签 card (rows with a 'tag' key) if (!isset($owner)) { $owner = UOJContext::userid(); } $show_write_buttons = !empty($show_write_buttons); $show_tags = !empty($show_tags); if (!isset($all_tags)) { $all_tags = array(); } $sidebar_user = queryUser($owner); // Queried exactly once per page view; the mini preview and the enlarged // modal both render from this single map. $activity = queryUserActivityHeatmap($owner); $heatmap_today_ts = strtotime(date('Y-m-d')); // Sunday of the current week (weeks are Monday-first), then back up to the // Monday 52 weeks before it: 53 columns x 7 rows ending at today. $heatmap_start_ts = $heatmap_today_ts + (7 - (int)date('N', $heatmap_today_ts)) * 86400 - 370 * 86400; // Month labels are only shown in the enlarged modal, spaced at least four // columns apart so short month names never overlap; a partial leading month // yields to the fuller month that starts right after it. $heatmap_month_labels = array(); $heatmap_candidates = array(); $heatmap_prev_month = null; for ($col = 0; $col < 53; $col++) { $month = (int)date('n', $heatmap_start_ts + $col * 7 * 86400); if ($month !== $heatmap_prev_month) { $heatmap_candidates[] = array($col, $month.'月'); $heatmap_prev_month = $month; } } $heatmap_last_col = -100; foreach ($heatmap_candidates as $candidate) { if ($candidate[0] - $heatmap_last_col < 4) { array_pop($heatmap_month_labels); } $heatmap_month_labels[$candidate[0]] = $candidate[1]; $heatmap_last_col = $candidate[0]; } ksort($heatmap_month_labels); // Build the 371 cells once and reuse the same markup in both grids. $heatmap_cells = ''; for ($col = 0; $col < 53; $col++) { for ($row = 0; $row < 7; $row++) { $ts = $heatmap_start_ts + ($col * 7 + $row) * 86400; $date = date('Y-m-d', $ts); $count = isset($activity[$date]) ? $activity[$date] : 0; if ($count <= 0) { $level = 0; } elseif ($count == 1) { $level = 1; } elseif ($count == 2) { $level = 2; } elseif ($count == 3) { $level = 3; } else { $level = 4; } if ($ts > $heatmap_today_ts) { $heatmap_cells .= ''; } else { $heatmap_cells .= ''; } } } $heatmap_total = array_sum($activity); ?>
<?= HTML::escape($owner) ?> Avatar
标签
暂无
活跃度 近 53 周
查看全年