2013-07-25 23:33:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Helpers {
|
|
|
|
public static function template($template) {
|
|
|
|
echo file_get_contents('templates/' . $template);
|
|
|
|
}
|
2013-07-28 19:45:21 +02:00
|
|
|
|
|
|
|
public static function angular($expression) {
|
|
|
|
return '{{' . $expression . '}}';
|
|
|
|
}
|
2013-08-01 04:01:41 +02:00
|
|
|
|
|
|
|
public static function formatBytes($bytes, $precision = 2) {
|
|
|
|
if ($bytes == 0)
|
|
|
|
return '0 MB';
|
|
|
|
|
|
|
|
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
|
|
|
|
|
|
|
$bytes = max($bytes, 0);
|
|
|
|
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
|
|
|
$pow = min($pow, count($units) - 1);
|
|
|
|
|
|
|
|
$bytes /= pow(1024, $pow);
|
|
|
|
|
|
|
|
return round($bytes, $precision) . ' ' . $units[$pow];
|
|
|
|
}
|
2013-09-01 04:20:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* timeago-style timestamp generator macro.
|
|
|
|
*
|
|
|
|
* @param string $timestamp A timestamp in SQL DATETIME syntax
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function timestamp( $timestamp ) {
|
|
|
|
if(gettype($timestamp) !== 'string' && get_class($timestamp) === 'DateTime'){
|
|
|
|
$timestamp = $timestamp->format('c');
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = date('c', strtotime($timestamp));
|
|
|
|
$content = date('F d, o \@ g:i:s a', strtotime($timestamp));
|
|
|
|
return '<abbr class="timeago" title="'.$title.'">'.$content.'</abbr>';
|
|
|
|
}
|
2013-07-25 23:33:04 +02:00
|
|
|
}
|