增加访问记录功能

This commit is contained in:
2023-06-28 11:12:30 +08:00
parent a12cca37e4
commit 65e1800c6f
18 changed files with 447 additions and 98 deletions

View File

@@ -77,7 +77,7 @@ function get_source_link($url)
{
if (empty($url)) {
$url = '/static/images/avatar.jpeg';
$url = '/static/images/avatar.png';
}
if (strpos($url, '/') === 0) {
return $url;
@@ -302,4 +302,26 @@ if (!function_exists('ua_htmlentities')) {
return htmlentities($string);
}
}
function show_time_ago($timestamp) {
$current_time = new DateTime();
$target_time = new DateTime("@$timestamp");
$interval = $current_time->diff($target_time);
if ($interval->y > 0) {
$result = $interval->format('%y 年前');
} elseif ($interval->m > 0) {
$result = $interval->format('%m 个月前');
} elseif ($interval->d > 0) {
$result = $interval->format('%d 天前');
} elseif ($interval->h > 0) {
$result = $interval->format('%h 小时前');
} elseif ($interval->i > 0) {
$result = $interval->format('%i 分钟前');
} else {
$result = $interval->format('%s 秒前');
}
return $result;
}