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

+19 -14
View File
@@ -11,29 +11,34 @@
namespace IPS\Member;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use function defined;
use function mb_strtolower;
use function ord;
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;
}
/**
* Letter photo generator for member accounts
*/
class _LetterPhoto
class LetterPhoto
{
/**
* @brief Member name
*/
protected $memberName = NULL;
protected ?string $memberName = NULL;
/**
* Create a new photo object
*
* @param string $name Member name
* @param string $name Member name
* @return void
*/
public function __construct( $name )
public function __construct( string $name )
{
$this->memberName = $name;
}
@@ -41,24 +46,24 @@ class _LetterPhoto
/**
* @brief Color saturation to use for HSV colors
*/
protected $colorCodeSaturation = .45;
protected float $colorCodeSaturation = .45;
/**
* @brief Color value to use for HSV colors
*/
protected $colorCodeValue = 0.575;
protected float $colorCodeValue = 0.575;
/**
* @brief If we have just generated a hue on this page load, store it to better randomize the next color
*/
protected static $lastHue = NULL;
protected static ?float $lastHue = NULL;
/**
* Return a unique hex color code based on the name.
*
* @return string
*/
public function generateColorCode()
public function generateColorCode() : string
{
/* If we've already generated a hue on this page load, use the golden ratio to find a number sufficiently distinct */
if( static::$lastHue )
@@ -75,13 +80,13 @@ class _LetterPhoto
return $this->convertRgbToHex( $this->convertHsvToRgb( $hue, $this->colorCodeSaturation, $this->colorCodeValue ) );
}
$hue = ( ( \ord( \mb_strtolower( $this->memberName ) ) - 97 ) / 25.0 ) + 0.25;
$hue = ( ( ord( mb_strtolower( $this->memberName ) ) - 97 ) / 25.0 ) + 0.25;
$hue *= 1.61803398875;
$hue *= (float) ( '1.' . rand() ) / 1;
if( rand( 0, 1 ) )
{
$float = (float) ( "1." . \ord( array_rand( range( 'a', 'z' ) ) ) );
$float = (float) ( "1." . ord( array_rand( range( 'a', 'z' ) ) ) );
$hue = abs( $float - $hue );
}
@@ -103,7 +108,7 @@ class _LetterPhoto
* @param float $v Value
* @return array
*/
protected function convertHsvToRgb( $h, $s, $v )
protected function convertHsvToRgb( float $h, float $s, float $v ): array
{
$rgb = array( $v, $v, $v );
$diff = ( $v <= 0.5 ) ? ( $v * ( 1.0 + $s ) ) : ( $v + $s - $v * $s );
@@ -155,7 +160,7 @@ class _LetterPhoto
* @param array $rgb RGB color values
* @return string
*/
protected function convertRgbToHex( array $rgb )
protected function convertRgbToHex( array $rgb ): string
{
return sprintf( "%02x%02x%02x", $rgb[0], $rgb[1], $rgb[2] );
}