summaryrefslogtreecommitdiffstats
path: root/inc/util.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r--inc/util.inc.php30
1 files changed, 21 insertions, 9 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 69eaf941..e459cc46 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -179,6 +179,13 @@ SADFACE;
$location .= '&' . implode('&', self::$redirectParams);
}
}
+ if (CONFIG_DEBUG) {
+ global $global_start;
+ $duration = microtime(true) - $global_start;
+ error_log('Redirect: ' . round($duration, 3) . 's, '
+ . Database::getQueryCount() . ' queries, '
+ . round(Database::getQueryTime(), 3) . 's query time total');
+ }
Header('Location: ' . $location);
exit(0);
}
@@ -227,18 +234,23 @@ SADFACE;
*
* @param float|int $bytes numeric value of the filesize to make readable
* @param int $decimals number of decimals to show, -1 for automatic
- * @return string human readable string representing the given filesize
+ * @param int $shift how many units to skip, i.e. if you pass in KiB or MiB
+ * @return string human readable string representing the given file size
*/
- public static function readableFileSize($bytes, $decimals = -1)
+ public static function readableFileSize($bytes, $decimals = -1, $shift = 0)
{
+ $bytes = round($bytes);
static $sz = array('Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
$factor = (int)floor((strlen($bytes) - 1) / 3);
- if ($factor == 0) {
+ if ($factor === 0) {
$decimals = 0;
- } elseif ($decimals === -1) {
- $decimals = 2 - floor((strlen($bytes) - 1) % 3);
+ } else {
+ $bytes = $bytes / pow(1024, $factor);
+ if ($decimals === -1) {
+ $decimals = 2 - floor(strlen((int)$bytes) - 1);
+ }
}
- return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . $sz[$factor];
+ return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor + $shift];
}
public static function sanitizeFilename($name)
@@ -484,7 +496,7 @@ SADFACE;
settype($ts, 'int');
if ($ts === 0)
return '???';
- static $TODAY = false, $ETODAY = false, $YESTERDAY = false, $YEAR = false;
+ static $TODAY = false, $ETODAY = false, $YESTERDAY = false, $YEARCUTOFF = false;
if (!$ETODAY) $ETODAY = strtotime('today 23:59:59');
if ($ts > $ETODAY) // TODO: Do we need strings for future too?
return date('d.m.Y H:i', $ts);
@@ -494,8 +506,8 @@ SADFACE;
if (!$YESTERDAY) $YESTERDAY = strtotime('yesterday 0:00');
if ($ts >= $YESTERDAY)
return Dictionary::translate('lang_yesterday') . ' ' . date('H:i', $ts);
- if (!$YEAR) $YEAR = strtotime('this year 1/1');
- if ($ts >= $YEAR)
+ if (!$YEARCUTOFF) $YEARCUTOFF = min(strtotime('-3 month'), strtotime('this year 1/1'));
+ if ($ts >= $YEARCUTOFF)
return date('d.m. H:i', $ts);
return date('d.m.Y', $ts);
}