From a3f57c8fd6b646fc0d026601d2edde00cee6b727 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 28 Jul 2009 23:56:46 +0100 Subject: [PATCH] make autodate work, and use it a bit --- core/util.inc.php | 22 +++++++++++++++++----- ext/view/theme.php | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index fbd45897..bf12be7a 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -93,14 +93,26 @@ function to_shorthand_int($int) { /** * Turn a date into a time, a date, an "X minutes ago...", etc * - * Currently missing step 2 - * * @retval string */ function autodate($date) { - $ts = strtotime($date); - // Step 2: ... - return date("Y-m-d", $ts); + $diff = time() - strtotime($date); + if ($diff<60) return $diff . " second" . plural($diff) . " ago"; $diff = round($diff/60); + if ($diff<60) return $diff . " minute" . plural($diff) . " ago"; $diff = round($diff/60); + if ($diff<24) return $diff . " hour" . plural($diff) . " ago"; $diff = round($diff/24); + if ($diff<7) return $diff . " day" . plural($diff) . " ago"; $diff = round($diff/7); + if ($diff<4) return $diff . " week" . plural($diff) . " ago"; + return "on " . date("F j, Y", strtotime($date)); +} + + +/** + * Return a pluraliser if necessary + * + * @retval string + */ +function plural($num, $single_form="", $plural_form="s") { + return ($num == 1) ? $single_form : $plural_form; } diff --git a/ext/view/theme.php b/ext/view/theme.php index 48ca7bc0..fc8a719f 100644 --- a/ext/view/theme.php +++ b/ext/view/theme.php @@ -65,9 +65,10 @@ class ViewImageTheme extends Themelet { $h_ip = html_escape($image->owner_ip); $h_source = html_escape($image->source); $i_owner_id = int_escape($owner->id); + $h_date = autodate($image->posted); $html = ""; - $html .= "

Uploaded by $h_owner"; + $html .= "

Uploaded by $h_owner $h_date"; if($user->is_admin()) { $html .= " ($h_ip)";