Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+18 -13
View File
@@ -11,30 +11,35 @@
namespace IPS\Output\Plugin;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Member;
use function defined;
use function floatval;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Template Plugin - Filesize
*/
class _Filesize
class Filesize
{
/**
* @brief Can be used when compiling CSS
*/
public static $canBeUsedInCss = FALSE;
public static bool $canBeUsedInCss = FALSE;
/**
* Run the plug-in
*
* @param string $data The initial data from the tag
* @param array $options Array of options
* @return array array( 'pre' => Code to eval before 'return', 'return' => Code to eval to return desired value )
* @return string array( 'pre' => Code to eval before 'return', 'return' => Code to eval to return desired value )
*/
public static function runPlugin( $data, $options )
public static function runPlugin( string $data, array $options ): string
{
return '\IPS\Output\Plugin\Filesize::humanReadableFilesize( ' . $data . ( ( isset( $options['decimal'] ) and $options['decimal'] ) ? ', TRUE' : '' ) . ' )';
}
@@ -42,15 +47,15 @@ class _Filesize
/**
* Get human readable filesize (to 2SF)
*
* @param int $sizeInBytes Size in bytes
* @param int|null $sizeInBytes Size in bytes
* @param bool $decimal If TRUE, will calculate based on decimal figures rather than binary
* @param bool $json If TRUE, will format for json
* @param bool $get If TRUE, will get the language string rather than add to stack
* @return string
*/
public static function humanReadableFilesize( $sizeInBytes, $decimal=FALSE, $json=FALSE, $get=FALSE )
public static function humanReadableFilesize( ?int $sizeInBytes, bool $decimal=FALSE, bool $json=FALSE, bool $get=FALSE ) : string
{
$sizeInBytes = \floatval( $sizeInBytes );
$sizeInBytes = floatval( $sizeInBytes );
foreach ( array( 'Y' => 80, 'Z' => 70, 'E' => 60, 'P' => 50, 'T' => 40, 'G' => 30, 'M' => 20, 'k' => 10 ) as $sig => $pow )
{
@@ -59,7 +64,7 @@ class _Filesize
{
if ( $get )
{
return sprintf( \IPS\Member::loggedIn()->language()->get( 'filesize_' . $sig ), round( ( $sizeInBytes / $raised ), 2 ) );
return sprintf( Member::loggedIn()->language()->get( 'filesize_' . $sig ), round( ( $sizeInBytes / $raised ), 2 ) );
}
else
{
@@ -70,14 +75,14 @@ class _Filesize
$format['json'] = TRUE;
}
return \IPS\Member::loggedIn()->language()->addToStack( 'filesize_' . $sig, FALSE, $format );
return Member::loggedIn()->language()->addToStack( 'filesize_' . $sig, FALSE, $format );
}
}
}
if ( $get )
{
return sprintf( \IPS\Member::loggedIn()->language()->get( 'filesize_b' ), $sizeInBytes );
return sprintf( Member::loggedIn()->language()->get( 'filesize_b' ), $sizeInBytes );
}
else
{
@@ -88,7 +93,7 @@ class _Filesize
$format['json'] = TRUE;
}
return \IPS\Member::loggedIn()->language()->addToStack( 'filesize_b', FALSE, $format );
return Member::loggedIn()->language()->addToStack( 'filesize_b', FALSE, $format );
}
}
}