1 ? 2 : 0) . $sizes[$i]); } } public static function revision() { $file = file(Cana::config()->dirs->root.'.hg/branchheads.cache'); $file = explode(' ',$file[0]); return trim($file[1]); } public static function relativeTime($timestamp){ $difference = time() - strtotime($timestamp); $periods = array('sec', 'min', 'hour', 'day', 'week', 'month', 'year', 'decade'); $lengths = array('60','60','24','7','4.35','12','10'); if ($difference > 0) { // this was in the past $ending = 'ago'; } else { // this was in the future $difference = -$difference; $ending = 'to go'; } for($j = 0; $difference >= $lengths[$j]; $j++) { $difference /= $lengths[$j]; }$difference = round($difference); if ($difference != 1) { $periods[$j].= 's'; } $text = $difference.' '.$periods[$j].' '.$ending; return $text; } public static function truncateByLines($string, $maxlines = 3) { $retVals = array(); $string = explode("\n",trim($string)); for ($x = 0; $x < $maxlines; $x++) { if (isset($string[$x])) { $retVals[] = $string[$x]; } } return implode("\n",$retVals); } public static function truncateByWord($string, $length = 100, $suffix = '…') { if (strlen($string) > $length) { $string = explode(' ', $string); $newString = ''; foreach ($string as $piece) { if (strlen($newString.' '.$piece) <= $length) { $newString .= ' '.$piece; } else { break; } } $string = trim($newString).$suffix; } return $string; } }