From 5d8813988b4b5ffad18af61b1f99ca346edf4bb2 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 27 Nov 2014 18:54:47 +0000 Subject: [PATCH] Added time since on page list --- index.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index.php b/index.php index 4c5154a..050bc6f 100755 --- a/index.php +++ b/index.php @@ -402,6 +402,25 @@ function human_filesize($bytes, $decimals = 2) $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor]; } +//from http://snippets.pro/snippet/137-php-convert-the-timestamp-to-human-readable-format/ +function human_time_since($time) +{ + $timediff = time() - $time; + $tokens = array ( + 31536000 => 'year', + 2592000 => 'month', + 604800 => 'week', + 86400 => 'day', + 3600 => 'hour', + 60 => 'minute', + 1 => 'second' + ); + foreach ($tokens as $unit => $text) { + if ($timediff < $unit) continue; + $numberOfUnits = floor($timdiffe / $unit); + return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'').' ago'; + } +} /////////////////////////////////////////// switch($_GET["action"]) @@ -511,6 +530,7 @@ switch($_GET["action"]) Size Last Editor Lasted Modified + Time Since \n"; foreach($pageindex as $pagename => $pagedetails) { @@ -519,6 +539,7 @@ switch($_GET["action"]) " . human_filesize($pagedetails->size) . " $pagedetails->lasteditor " . date("l jS \of F Y \a\\t h:ia T", $pagedetails->lastmodified) . " + " . human_time_since($pagedetails->lastmodified) . " \n"; } $content .= " ";