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

+42 -24
View File
@@ -11,9 +11,15 @@
namespace IPS\Node;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Member;
use IPS\Theme;
use function defined;
use function substr;
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;
}
@@ -25,24 +31,24 @@ trait Colorize
/**
* @brief Table column name that holds the feature color hex
*/
public static $featureColumnName = 'feature_color';
public static string $featureColumnName = 'feature_color';
/**
* @brief Cache the calculated formatted title for this node
*/
protected $formattedTitle = NULL;
protected ?string $formattedTitle = NULL;
/**
* @brief Cache the formatted text colour for this node
*/
protected $featureTextColor = NULL;
protected ?string $featureTextColor = NULL;
/**
* Get HTML formatted title. Allows apps or nodes to format the title, such as adding different colours, etc
*
* @return string
*/
public function get__formattedTitle()
public function get__formattedTitle(): string
{
if ( $this->formattedTitle === NULL )
{
@@ -54,19 +60,30 @@ trait Colorize
}
else
{
$this->formattedTitle = \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->formattedTitle( $this );
$this->formattedTitle = Theme::i()->getTemplate( 'global', 'core', 'front' )->formattedTitle( $this );
}
}
return $this->formattedTitle;
}
/**
* Get the featured color for use in CSS
*
* @return string|null
*/
public function get__featureColor(): ?string
{
$columnName = static::$featureColumnName;
return $this->$columnName;
}
/**
* Get the featured text color for use in CSS
*
* @return string
* @return string|null
*/
public function get__featureTextColor()
public function get__featureTextColor(): ?string
{
if ( $this->featureTextColor === NULL )
{
@@ -83,26 +100,27 @@ trait Colorize
return $this->featureTextColor;
}
/**
* Static method to fetch the text colour based on the the contrast from the background color
*
* @return string
* @param $featureColor
* @return string
*/
public static function featureTextColor( $featureColor )
public static function featureTextColor( $featureColor ): string
{
$hexColor = str_replace( '#', '', $featureColor );
$blackColor = '000000';
$textColor = '#ffffff';
/* Use luminosity contrast algorithm to determine font color */
$r1 = hexdec( \substr( $hexColor, 0, 2 ) );
$g1 = hexdec( \substr( $hexColor, 2, 2 ) );
$b1 = hexdec( \substr( $hexColor, 4, 2 ) );
$r1 = hexdec( substr( $hexColor, 0, 2 ) );
$g1 = hexdec( substr( $hexColor, 2, 2 ) );
$b1 = hexdec( substr( $hexColor, 4, 2 ) );
$r2 = hexdec( \substr( $blackColor, 0, 2 ) );
$g2 = hexdec( \substr( $blackColor, 2, 2 ) );
$b2 = hexdec( \substr( $blackColor, 4, 2 ) );
$r2 = hexdec( substr( $blackColor, 0, 2 ) );
$g2 = hexdec( substr( $blackColor, 2, 2 ) );
$b2 = hexdec( substr( $blackColor, 4, 2 ) );
$l1 = 0.2126 * pow( $r1 / 255, 2.2 ) + 0.7152 * pow( $g1 / 255, 2.2 ) + 0.0722 * pow( $b1 / 255, 2.2 );
$l2 = 0.2126 * pow( $r2 / 255, 2.2 ) + 0.7152 * pow( $g2 / 255, 2.2 ) + 0.0722 * pow( $b2 / 255, 2.2 );
@@ -133,9 +151,9 @@ trait Colorize
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
* @param bool $escape If the title should be escaped for HTML output. If FALSE, the feature color will not be used, because that requires HTML output
* @return \IPS\Http\Url
* @return mixed
*/
public static function titleFromIndexData( $indexData, $itemData, $containerData, $escape = TRUE )
public static function titleFromIndexData(array $indexData, array $itemData, ?array $containerData, bool $escape = TRUE ): mixed
{
if ( !$escape or !isset( $containerData[ static::$databasePrefix . static::$featureColumnName ] ) )
{
@@ -143,17 +161,17 @@ trait Colorize
}
$node = $containerData;
$node['title'] = \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $indexData['index_container_id'], 'NULL', array( 'escape' => true ) );
$node['title'] = Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $indexData['index_container_id'], 'NULL', array( 'escape' => true ) );
$node['text_color'] = static::featureTextColor( $node[ static::$databasePrefix . static::$featureColumnName ] );
/* Normalize */
$node['feature_color'] = $node[ static::$databasePrefix . static::$featureColumnName ];
$title = \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->formattedTitle( $node );
$title = Theme::i()->getTemplate( 'global', 'core', 'front' )->formattedTitle( $node );
if ( $indexData['index_club_id'] and isset( $containerData['_club'] ) )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'club_container_title', FALSE, array( 'sprintf' => array( $containerData['_club']['name'] ), 'htmlsprintf' => array( $title ) ) );
return Member::loggedIn()->language()->addToStack( 'club_container_title', FALSE, array( 'sprintf' => array( $containerData['_club']['name'] ), 'htmlsprintf' => array( $title ) ) );
}
else
{