From 23f0b77f33f45badc0e2a0b5637def29ee5de9d9 Mon Sep 17 00:00:00 2001 From: kanoi Date: Fri, 19 Sep 2014 22:06:53 +1000 Subject: [PATCH] php - make the share age function reusable --- pool/base.php | 37 ++++++++++++++++++++++++++++++++++++- pool/page_workers.php | 32 +------------------------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/pool/base.php b/pool/base.php index aab770b9..8f26c8b1 100644 --- a/pool/base.php +++ b/pool/base.php @@ -18,6 +18,41 @@ function adddbg($str) } } # +function howlongago($sec) +{ + if ($sec < 60) + $des = $sec.'s'; + else + { + $sec = round($sec/60); + if ($sec < 60) + $des = $sec.'min'; + else + { + $sec = round($sec/60); + if ($sec < 24) + { + $des = $sec.'hr'; + if ($sec != 1) + $des .= 's'; + } + else + { + $sec = round($sec/24); + if ($sec < 9999) + { + $des = $sec.'day'; + if ($sec != 1) + $des .= 's'; + } + else + $des = 'never'; + } + } + } + return $des; +} +# function btcfmt($amt) { $amt /= 100000000; @@ -240,7 +275,7 @@ function validUserPass($user, $pass) { $rep = checkPass($user, $pass); if ($rep != null) - $ans = repDecode($rep); + $ans = repDecode($rep); usleep(100000); // Max 10x per second if ($rep != null && $ans['STATUS'] == 'ok') { diff --git a/pool/page_workers.php b/pool/page_workers.php index 625630e6..7129ab60 100644 --- a/pool/page_workers.php +++ b/pool/page_workers.php @@ -42,37 +42,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff, $ld = ' '; $pg .= "$ld"; - if ($lst < 60) - $lstdes = $lst.'s'; - else - { - $lst = round($lst/60); - if ($lst < 60) - $lstdes = $lst.'min'; - else - { - $lst = round($lst/60); - if ($lst < 24) - { - $lstdes = $lst.'hr'; - if ($lst != 1) - $lstdes .= 's'; - } - else - { - $lst = round($lst/24); - if ($lst < 9999) - { - $lstdes = $lst.'day'; - if ($lst != 1) - $lstdes .= 's'; - } - else - $lstdes = 'never'; - } - } - } - $pg .= "$lstdes"; + $pg .= ''.howlongago($lst).''; $shareacc = number_format($ans['w_shareacc:'.$i], 0); $totshare += $ans['w_shareacc:'.$i];