make autodate work, and use it a bit
This commit is contained in:
parent
3dc3f5e8cb
commit
a3f57c8fd6
2 changed files with 19 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 .= "<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()) {
|
||||
$html .= " ($h_ip)";
|
||||
|
|
Reference in a new issue