Version 5.0.0 beta 2

This commit is contained in:
Neo committed 2025-12-19 16:39:01 -08:00
1 parent 15c7beabc5
commit f61b0da85d
181 files changed
+3182 -1533

No files matched your search

+15
View File
@@ -656,6 +656,21 @@ class Area
}
}
/* Make sure that the widget actually exists, otherwise ignore it.
This can be an issue if a widget was added and now no longer exists in the system. */
try
{
if( !Widget::isValidWidget( Application::load( $block['app'] ), $block['key'] ) )
{
return $this;
}
}
catch( Exception )
{
return $this;
}
/* Load configuration */
if ( empty( $block['configuration'] ) or !is_array( $block['configuration'] ) )
{
+34
View File
@@ -0,0 +1,34 @@
<?php
/**
* @brief Polymorphic
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since Oct 2024
*/
namespace IPS\Widget;
/* To prevent PHP errors (extending class does not exist) revealing path */
use function defined;
use function header;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
interface Polymorphic
{
/**
* Get the base key. When the class name is dynamically generated, we need to use the base key to look in the database and find the actual base configuration
*
* @return string
*/
public static function getBaseKey() : string;
}
+46 -3
View File
@@ -494,7 +494,7 @@ abstract class Widget
*/
public function getSupportedLayouts() : array
{
if ( !isset( static::$baseWidgetConfig[ $this::class ]['layouts'] ) OR empty( static::$baseWidgetConfig[ $this::class ]['layouts'] ) )
if ( !isset( static::$baseWidgetConfig[ $this::class ]['layouts'] ) OR !is_array( static::$baseWidgetConfig[ $this::class ]['layouts'] ) )
{
$layouts = ['table'];
if ( $this->isCustomizableWidget() )
@@ -718,6 +718,17 @@ abstract class Widget
}
$class = '\IPS\\' . $parent->directory . '\widgets\\' . $widgetKey;
$baseWidgetKey = $widgetKey;
if ( class_exists( $class ) and in_array( "IPS\\Widget\\Polymorphic", class_implements( $class ) ) )
{
$baseWidgetKey = $class::getBaseKey();
}
/* Is this a valid widget? */
if( !static::isValidWidget( $parent, $baseWidgetKey ) )
{
throw new OutOfRangeException;
}
/* Return */
if ( class_exists( $class ) )
@@ -732,6 +743,37 @@ abstract class Widget
throw new OutOfRangeException;
}
/**
* Make sure that the widget actually is supported by the app
*
* @param Application|string $app
* @param string $widgetKey
* @return bool
*/
public static function isValidWidget( Application|string $app, string $widgetKey ) : bool
{
/* Is this a valid widget? */
try
{
$cache = Store::i()->widgets;
}
catch( OutOfRangeException )
{
static::appDefaults( $app );
$cache = Store::i()->widgets;
}
$app = ( $app instanceof Application ) ? $app->directory : $app;
$class = '\IPS\\' . $app . '\widgets\\' . $widgetKey;
if ( class_exists( $class ) and in_array( "IPS\\Widget\\Polymorphic", class_implements( $class ) ) )
{
$widgetKey = $class::getBaseKey();
}
return array_key_exists( $widgetKey, $cache[ $app ] );
}
/**
* Widget Types
@@ -1183,11 +1225,12 @@ abstract class Widget
/**
* Get default widgets for an application
*
* @param Application $app The application
* @param Application|string $app The application
* @return array
*/
public static function appDefaults( Application $app ): array
public static function appDefaults( Application|string $app ): array
{
$app = is_string( $app ) ? Application::load( $app ) : $app;
if ( !isset( Store::i()->widgets ) )
{
$widgets = array();