From b6daee1f526bd1cd9cb661304f156cbf0dc24c64 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 5 Mar 2018 15:45:57 +0100 Subject: [inc/Util] Print profiling info to error_log on redirect --- inc/util.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'inc/util.inc.php') diff --git a/inc/util.inc.php b/inc/util.inc.php index 69eaf941..c0617310 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); } -- cgit v1.2.3-55-g7522 From 7780372ee5c8f819c0ad6c6c637254496de42d0b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Mar 2018 11:48:18 +0100 Subject: [inc/Util] readableFileSize: Use thin space, determine decimals after division --- inc/util.inc.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'inc/util.inc.php') diff --git a/inc/util.inc.php b/inc/util.inc.php index c0617310..52e1dbca 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -234,18 +234,22 @@ 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 + * @return string human readable string representing the given file size */ public static function readableFileSize($bytes, $decimals = -1) { + $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 = round($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]; } public static function sanitizeFilename($name) -- cgit v1.2.3-55-g7522 From d66b2b66dc5b8982bef236a40a9422906a175e92 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Mar 2018 13:45:51 +0100 Subject: [inc/Util] readableFileSize: Remove superfluous round() --- inc/util.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/util.inc.php') diff --git a/inc/util.inc.php b/inc/util.inc.php index 52e1dbca..9f6f63db 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -244,7 +244,7 @@ SADFACE; if ($factor === 0) { $decimals = 0; } else { - $bytes = round($bytes / pow(1024, $factor)); + $bytes = $bytes / pow(1024, $factor); if ($decimals === -1) { $decimals = 2 - floor(strlen((int)$bytes) - 1); } -- cgit v1.2.3-55-g7522 From bfe34ff61df650b02610767af673644144f015eb Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 2 Jan 2019 15:26:04 +0100 Subject: [inc/Util] Improve prettyTime year cutoff logic Closes #3518 --- inc/util.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc/util.inc.php') diff --git a/inc/util.inc.php b/inc/util.inc.php index 9f6f63db..1a5cbefe 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -495,7 +495,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); @@ -505,8 +505,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); } -- cgit v1.2.3-55-g7522 From 54a0a4c9b920bce1dc4e93d2cf05ebbea6502be0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 28 Jan 2019 13:48:03 +0100 Subject: [inc/Util] readableFileSize: support input in KB/MB/... --- inc/util.inc.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'inc/util.inc.php') diff --git a/inc/util.inc.php b/inc/util.inc.php index 1a5cbefe..e459cc46 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -234,9 +234,10 @@ SADFACE; * * @param float|int $bytes numeric value of the filesize to make readable * @param int $decimals number of decimals to show, -1 for automatic + * @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'); @@ -249,7 +250,7 @@ SADFACE; $decimals = 2 - floor(strlen((int)$bytes) - 1); } } - return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor]; + return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor + $shift]; } public static function sanitizeFilename($name) -- cgit v1.2.3-55-g7522