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

+33 -25
View File
@@ -11,21 +11,29 @@
namespace IPS\Output\Plugin;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Settings;
use IPS\Theme;
use function defined;
use function str_replace;
use function strlen;
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;
}
/**
* Template Plugin - hextorgb
*/
class _Hextorgb
class Hextorgb
{
/**
* @brief Can be used when compiling CSS
*/
public static $canBeUsedInCss = TRUE;
public static bool $canBeUsedInCss = TRUE;
/**
* Run the plug-in. Take #ffffff and returns 255,255,255, for example
@@ -34,7 +42,7 @@ class _Hextorgb
* @param array $options Array of options
* @return string Code to eval
*/
public static function runPlugin( $data, $options )
public static function runPlugin( string $data, array $options ): string
{
if( $data[0] !== '$' ){
$data = "'" . $data . "'";
@@ -52,62 +60,62 @@ class _Hextorgb
/**
* Convert Hex value to RGB
*
* @param string $data Hex color code
* @param string $opacity Opacity (0-1) or Setting/Theme Setting name
* @param string $data Hex color code
* @param string $opacity Opacity (0-1) or Setting/Theme Setting name
* @return string
*/
public static function convertToRGB( $data, $opacity )
public static function convertToRGB( string $data, string $opacity ): string
{
$output = array();
/* If a theme setting key has been passed in, then use that as the value */
if ( isset( \IPS\Theme::i()->settings[ $data ] ) )
if ( isset( Theme::i()->settings[ $data ] ) )
{
$data = \IPS\Theme::i()->settings[ $data ];
$data = Theme::i()->settings[ $data ];
}
/* If a regular setting key has been passed in, then use that as the value */
if ( isset( \IPS\Settings::i()->$data ) )
if ( isset( Settings::i()->$data ) )
{
$data = \IPS\Settings::i()->$data;
$data = Settings::i()->$data;
}
/* If a theme setting key has been passed in, then use that as the opacity */
if ( isset( \IPS\Theme::i()->settings[ $opacity ] ) )
if ( isset( Theme::i()->settings[ $opacity ] ) )
{
$opacity = \IPS\Theme::i()->settings[ $opacity ];
$opacity = Theme::i()->settings[ $opacity ];
}
/* If a regular setting key has been passed in, then use that as the opacity */
if ( isset( \IPS\Settings::i()->$opacity ) )
if ( isset( Settings::i()->$opacity ) )
{
$opacity = \IPS\Settings::i()->$opacity;
$opacity = Settings::i()->$opacity;
}
/* Basic validation */
if( !preg_match( "/^#?[0-9a-fA-F]+$/", $data ) OR ( \strlen( str_replace( '#', '', $data ) ) !== 3 AND \strlen( str_replace( '#', '', $data ) ) !== 6 ) )
if( !preg_match( "/^#?[0-9a-fA-F]+$/", $data ) OR ( strlen( str_replace( '#', '', $data ) ) !== 3 AND strlen( str_replace( '#', '', $data ) ) !== 6 ) )
{
return "htmlspecialchars( '" . $data . "', ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', FALSE )";
}
$data = str_replace( '#', '', $data );
if ( \strlen( $data ) == 3 )
if ( strlen( $data ) == 3 )
{
$output[] = hexdec( \substr( $data, 0, 1 ) . \substr( $data, 0, 1 ) ); // R
$output[] = hexdec( \substr( $data, 1, 1 ) . \substr( $data, 1, 1 ) ); // G
$output[] = hexdec( \substr( $data, 2, 1 ) . \substr( $data, 2, 1 ) ); // B
$output[] = hexdec( substr( $data, 0, 1 ) . substr( $data, 0, 1 ) ); // R
$output[] = hexdec( substr( $data, 1, 1 ) . substr( $data, 1, 1 ) ); // G
$output[] = hexdec( substr( $data, 2, 1 ) . substr( $data, 2, 1 ) ); // B
}
else
{
$output[] = hexdec( \substr( $data, 0, 2 ) ); // R
$output[] = hexdec( \substr( $data, 2, 2 ) ); // G
$output[] = hexdec( \substr( $data, 4, 2 ) ); // B
$output[] = hexdec( substr( $data, 0, 2 ) ); // R
$output[] = hexdec( substr( $data, 2, 2 ) ); // G
$output[] = hexdec( substr( $data, 4, 2 ) ); // B
}
if( isset( $opacity ) && $opacity !== '1' )
{
return "rgba(" . implode( ',', $output ) . "," . \str_replace( ',', '.', $opacity ) . ")";
return "rgba(" . implode( ',', $output ) . "," . str_replace( ',', '.', $opacity ) . ")";
}
else
{