| } | ||
| - // New capability: Allow Files to compare themselves to other Files | ||
| public function compare(File $other): int { | ||
| - // 1. Sort Directories before Files | ||
| if ($this->isDir !== $other->isDir) { | ||
| return $this->isDir ? -1 : 1; | ||
| } | ||
| - // 2. Sort Alphabetically by Name | ||
| + | ||
| return strcasecmp($this->name, $other->name); | ||
| } | ||
| public function render(FileRenderer $renderer): void { | ||
| $renderer->renderFileItem( | ||
| $this->name, | ||
| $this->sha, | ||
| $this->mode, | ||
| $this->getIconClass(), | ||
| - $this->getTimeElapsed(), | ||
| + $this->timestamp, | ||
| $this->isDir ? '' : $this->getFormattedSize() | ||
| ); | ||
| } | ||
| - | ||
| - // ... [Rest of the class methods: getIconClass, getFormattedSize, etc. remain unchanged] ... | ||
| private function getIconClass(): string { | ||
| fclose($handle); | ||
| return ($read !== false) ? $read : ''; | ||
| - } | ||
| - | ||
| - private function getTimeElapsed(): string { | ||
| - if (!$this->timestamp) return ''; | ||
| - $diff = time() - $this->timestamp; | ||
| - if ($diff < 5) return 'just now'; | ||
| - $tokens = [ | ||
| - 31536000 => 'year', 2592000 => 'month', 604800 => 'week', | ||
| - 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' | ||
| - ]; | ||
| - foreach ($tokens as $unit => $text) { | ||
| - if ($diff < $unit) continue; | ||
| - $num = floor($diff / $unit); | ||
| - return $num . ' ' . $text . (($num > 1) ? 's' : '') . ' ago'; | ||
| - } | ||
| - return 'just now'; | ||
| } | ||
| } | ||
| string $mode, | ||
| string $iconClass, | ||
| - string $time, | ||
| + int $timestamp, | ||
| string $size = '' | ||
| ): void; | ||
| + | ||
| + public function renderTime(int $timestamp): void; | ||
| } | ||
| string $mode, | ||
| string $iconClass, | ||
| - string $time, | ||
| + int $timestamp, | ||
| string $size = '' | ||
| ): void { | ||
| - // UPDATED: Added '&name=' to the URL | ||
| $url = '?repo=' . urlencode($this->repoSafeName) . '&hash=' . $sha . '&name=' . urlencode($name); | ||
| } | ||
| - if ($time) { | ||
| - echo '<span class="file-date" style="color: #8b949e; font-size: 0.8em; margin-left: auto;">' . $time . '</span>'; | ||
| + if ($timestamp > 0) { | ||
| + echo '<span class="file-date" style="color: #8b949e; font-size: 0.8em; margin-left: auto;">'; | ||
| + $this->renderTime($timestamp); | ||
| + echo '</span>'; | ||
| } | ||
| echo '</a>'; | ||
| + } | ||
| + | ||
| + public function renderTime(int $timestamp): void { | ||
| + if (!$timestamp) { | ||
| + echo 'never'; | ||
| + return; | ||
| + } | ||
| + | ||
| + $diff = time() - $timestamp; | ||
| + if ($diff < 5) { | ||
| + echo 'just now'; | ||
| + return; | ||
| + } | ||
| + | ||
| + $tokens = [ | ||
| + 31536000 => 'year', 2592000 => 'month', 604800 => 'week', | ||
| + 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' | ||
| + ]; | ||
| + | ||
| + foreach ($tokens as $unit => $text) { | ||
| + if ($diff < $unit) continue; | ||
| + $num = floor($diff / $unit); | ||
| + echo $num . ' ' . $text . (($num > 1) ? 's' : '') . ' ago'; | ||
| + return; | ||
| + } | ||
| + echo 'just now'; | ||
| } | ||
| } | ||
| <?php | ||
| } | ||
| - | ||
| - protected function time_elapsed_string($timestamp) { | ||
| - if (!$timestamp) return 'never'; | ||
| - $diff = time() - $timestamp; | ||
| - if ($diff < 5) return 'just now'; | ||
| - $tokens = [31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second']; | ||
| - foreach ($tokens as $unit => $text) { | ||
| - if ($diff < $unit) continue; | ||
| - $num = floor($diff / $unit); | ||
| - return $num . ' ' . $text . (($num > 1) ? 's' : '') . ' ago'; | ||
| - } | ||
| - return 'just now'; | ||
| - } | ||
| } | ||
| if ($main) { | ||
| - $git->history('HEAD', 1, function($c) { | ||
| - echo '<p style="margin-top: 8px; color: #58a6ff;">' . $this->time_elapsed_string($c->date) . '</p>'; | ||
| + $git->history('HEAD', 1, function($c) use ($repo) { | ||
| + $renderer = new HtmlFileRenderer($repo['safe_name']); | ||
| + echo '<p style="margin-top: 8px; color: #58a6ff;">'; | ||
| + $renderer->renderTime($c->date); | ||
| + echo '</p>'; | ||
| }); | ||
| } | ||
| Author | Dave Jarvis <email> |
|---|---|
| Date | 2026-02-08 22:44:49 GMT-0800 |
| Commit | c7742cb3c580dc804d878b1a5f4528129a35a78c |
| Parent | 25fd48d |
| Delta | 41 lines added, 42 lines removed, 1-line decrease |