make autodate work, and use it a bit

This commit is contained in:
Shish 2009-07-28 23:56:46 +01:00
parent 3dc3f5e8cb
commit a3f57c8fd6
2 changed files with 19 additions and 6 deletions

View file

@ -93,14 +93,26 @@ function to_shorthand_int($int) {
/** /**
* Turn a date into a time, a date, an "X minutes ago...", etc * Turn a date into a time, a date, an "X minutes ago...", etc
* *
* Currently missing step 2
*
* @retval string * @retval string
*/ */
function autodate($date) { function autodate($date) {
$ts = strtotime($date); $diff = time() - strtotime($date);
// Step 2: ... if ($diff<60) return $diff . " second" . plural($diff) . " ago"; $diff = round($diff/60);
return date("Y-m-d", $ts); 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;
} }

View file

@ -65,9 +65,10 @@ class ViewImageTheme extends Themelet {
$h_ip = html_escape($image->owner_ip); $h_ip = html_escape($image->owner_ip);
$h_source = html_escape($image->source); $h_source = html_escape($image->source);
$i_owner_id = int_escape($owner->id); $i_owner_id = int_escape($owner->id);
$h_date = autodate($image->posted);
$html = ""; $html = "";
$html .= "<p>Uploaded by <a href='".make_link("user/$h_owner")."'>$h_owner</a>"; $html .= "<p>Uploaded by <a href='".make_link("user/$h_owner")."'>$h_owner</a> $h_date";
if($user->is_admin()) { if($user->is_admin()) {
$html .= " ($h_ip)"; $html .= " ($h_ip)";