mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Rename and update bytesToSizeString function and move it to heleprs.php with human_filesize name
This commit is contained in:
@@ -532,7 +532,7 @@ class XML_Response
|
||||
"src=\"{$this->server['server']['url']}/covers/{$dir}/{$this->release->$column}{$dcov}.jpg\" ".
|
||||
"width=\"120\" alt=\"{$this->release->searchname}\" />\n";
|
||||
}
|
||||
$size = Utility::bytesToSizeString($this->release->size);
|
||||
$size = human_filesize($this->release->size);
|
||||
$this->cdata .=
|
||||
"\t<li>ID: <a href=\"{$this->server['server']['url']}/details/{$this->release->guid}\">{$this->release->guid}</a></li>\n".
|
||||
"\t<li>Name: {$this->release->searchname}</li>\n".
|
||||
|
||||
@@ -258,17 +258,6 @@ class Utility
|
||||
return $prefix.implode(DS, $elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $text
|
||||
*/
|
||||
public static function stripBOM(&$text): void
|
||||
{
|
||||
$bom = pack('CCC', 0xef, 0xbb, 0xbf);
|
||||
if (0 === strncmp($text, $bom, 3)) {
|
||||
$text = substr($text, 3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips non-printing characters from a string.
|
||||
*
|
||||
@@ -509,27 +498,6 @@ class Utility
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get human readable size string from bytes.
|
||||
*
|
||||
* @param int $size Bytes number to convert.
|
||||
* @param int $precision How many floating point units to add.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function bytesToSizeString($size, $precision = 0): string
|
||||
{
|
||||
static $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
$step = 1024;
|
||||
$i = 0;
|
||||
while (($size / $step) > 0.9) {
|
||||
$size /= $step;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return round($size, $precision).$units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
2018-07-25 DariusIII
|
||||
* Chg: Rename and update bytesToSizeString function and move it to heleprs.php with human_filesize name
|
||||
* Fix: Fix wrong namespace for Blacklight\utility\Utility class in XML_Response class
|
||||
2018-07-24 DariusIII
|
||||
* Chg: Small updates/fixed for used regexes in Categorize class
|
||||
|
||||
@@ -165,9 +165,8 @@ if (! function_exists('makeFieldLinks')) {
|
||||
|
||||
if (! function_exists('createGUID')) {
|
||||
/**
|
||||
* Create a GUID for a release.
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
function createGUID(): string
|
||||
{
|
||||
@@ -202,4 +201,21 @@ if (! function_exists('makeFieldLinks')) {
|
||||
return new Color($string);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('human_filesize')) {
|
||||
|
||||
/**
|
||||
* @param $bytes
|
||||
* @param int $decimals
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function human_filesize($bytes, $decimals = 0): string
|
||||
{
|
||||
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
|
||||
$factor = floor((\strlen($bytes) - 1) / 3);
|
||||
|
||||
return round(sprintf("%.{$decimals}f", $bytes / (1024 ** $factor))) . @$size[$factor];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,11 +126,11 @@ class QueueController extends BasePageController
|
||||
if ($status !== false) {
|
||||
$output .=
|
||||
"<div class='container text-center' style='display:block;'>
|
||||
<div style='width:16.666666667%;float:left;'><b>Avg Speed:</b><br /> ".Utility::bytesToSizeString($status['AverageDownloadRate'], 2)."/s </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Speed:</b><br /> ".Utility::bytesToSizeString($status['DownloadRate'], 2)."/s </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Limit:</b><br /> ".Utility::bytesToSizeString($status['DownloadLimit'], 2)."/s </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Queue Left(no pars):</b><br /> ".Utility::bytesToSizeString($status['RemainingSizeLo'], 2)." </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Free Space:</b><br /> ".Utility::bytesToSizeString($status['FreeDiskSpaceMB'] * 1024000, 2)." </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Avg Speed:</b><br /> ".human_filesize($status['AverageDownloadRate'], 2)."/s </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Speed:</b><br /> ".human_filesize($status['DownloadRate'], 2)."/s </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Limit:</b><br /> ".human_filesize($status['DownloadLimit'], 2)."/s </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Queue Left(no pars):</b><br /> ".human_filesize($status['RemainingSizeLo'], 2)." </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Free Space:</b><br /> ".human_filesize($status['FreeDiskSpaceMB'] * 1024000, 2)." </div>
|
||||
<div style='width:16.666666667%;float:left;'><b>Status:</b><br /> ".($status['Download2Paused'] === 1 ? 'Paused' : 'Downloading').' </div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user