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

+96
View File
@@ -0,0 +1,96 @@
<?php
namespace IPS\Output\UI;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Content\Comment as BaseComment;
use IPS\Content\Item as BaseItem;
use IPS\Helpers\Form\FormAbstract;
use IPS\Helpers\Menu\MenuItem;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
abstract class Comment
{
/**
* This needs to be declared in any child classes as well
*
* @var ?string
*/
public static ?string $class = NULL;
/**
* Can be used to add additional css classes to the comment
*
* @param BaseComment $comment
* @return string
*/
public function css( BaseComment $comment ): string
{
return '';
}
/**
* Can be used to add additional data attributes to the comment
*
* @param BaseComment $comment
* @return string
*/
public function dataAttributes( BaseComment $comment ): string
{
return '';
}
/**
* Can be used to attach additional content to the author panel
*
* @param BaseComment $comment
* @return string
*/
public function authorPanel( BaseComment $comment ): string
{
return '';
}
/**
* returns additional menu items for the comment menu
*
* @param BaseComment $comment
* @return array<string,MenuItem>
*/
public function menuItems( BaseComment $comment ): array
{
return [];
}
/**
* Add elements to the comment form
*
* @param BaseComment|null $comment
* @param BaseItem $item
* @return array<string,FormAbstract>
*/
public function formElements( ?BaseComment $comment, BaseItem $item ): array
{
return [];
}
/**
* Triggered after the comment form is saved
*
* @param BaseComment $comment
* @param array $values
* @return void
*/
public function formPostSave( BaseComment $comment, array $values ): void
{
}
}
+166
View File
@@ -0,0 +1,166 @@
<?php
namespace IPS\Output\UI;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Content\Item as BaseItem;
use IPS\Helpers\Badge\Icon;
use IPS\Helpers\Form\FormAbstract;
use IPS\Helpers\Table\Content;
use IPS\Node\Model;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
abstract class Item
{
/**
* This needs to be declared in any child classes as well
*
* @var string|null
*/
public static ?string $class = NULL;
/**
* Can be used to add additional css classes to the item
*
* @param BaseItem $item
* @return string
*/
public function css( BaseItem $item ): string
{
return '';
}
/**
* Can be used to add additional data attributes to the item
*
* @param BaseItem $item
* @return string
*/
public function dataAttributes( BaseItem $item ): string
{
return '';
}
/**
* returns additional menu items for the moderation menu
*
* @param BaseItem $item
* @return array
*/
public function menuItems( BaseItem $item ): array
{
return [];
}
/**
* Returns additional badge icons to display in the header
*
* @param BaseItem $item
* @return array<Icon>
*/
public function badges( BaseItem $item ) : array
{
return [];
}
/**
* Add elements to the item form.
* This method returns all elements that will be added.
* By default, all elements will be added in order at the end of the form.
* To specify placement within the form, @see FormAbstract::setPosition().
*
* @param BaseItem|null $item
* @param Model|null $container
* @return array<string,FormAbstract>
*/
public function formElements( ?BaseItem $item, ?Model $container ): array
{
return [];
}
/**
* Called after the Item form is saved
*
* @param BaseItem $item
* @param array $values
* @return void
*/
public function formPostSave( BaseItem $item, array $values ): void
{
}
/**
* Display content in the contextual sidebar
*
* @param BaseItem $item
* @return string
*/
public function sidebar( BaseItem $item ) : string
{
return "";
}
/**
* Add custom sort options to the content table for this class
* @note $item will ALWAYS be null.
*
* @param BaseItem|null $item
* @param Content $table
* @return array
*/
public function contentTableSortOptions( ?BaseItem $item, Content $table ) : array
{
return [];
}
/**
* Return the sort direction for the selected sort option,
* or NULL to use the default parent method.
*
* @note $item will ALWAYS be null.
*
* @param BaseItem|null $item
* @param Content $table
* @param string $sortBy
* @return string|null
*/
public function contentTableSortDirection( ?BaseItem $item, Content $table, string $sortBy ) : string|null
{
return null;
}
/**
* Add custom filters to the content table for this class
* @note $item will ALWAYS be null.
*
* @param BaseItem|null $item
* @param Content $table
* @return array
*/
public function contentTableFilters( ?BaseItem $item, Content $table ) : array
{
return [];
}
/**
* Add custom conditions to the where clause for a content table.
* @note $item will ALWAYS be null.
*
* @param BaseItem|null $item
* @param Content $table
* @return array
*/
public function contentTableWhere( ?BaseItem $item, Content $table ) : array
{
return [];
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace IPS\Output\UI;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Helpers\Menu\MenuItem;
use IPS\Member as MemberClass;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
abstract class MenuExtension
{
/**
* Used to add additional links to the user account menu
*
* @param string $position ( can be content, settings, logout )
* @return array<MenuItem>
*/
public function accountMenu( string $position = 'content' ): array
{
return [];
}
/**
* Used to add items to the mobile navigation Menu
*
* @param string $position (can be content, settings, logout)
* @return array<MenuItem>
*/
public function mobileMenu( string $position = 'content' ) : array
{
return [];
}
/**
* Used to add additional content to userbar
*
* @return string
*/
public function userNav(): string
{
return '';
}
/**
* Used to add content to the mobile navigation header
*
* @param string $position Where the code will be inserted (header/footer)
* @param string $iconLocation Where the main icons are currently located (header/footer)
* @return string
*/
public function mobileNav( string $position, string $iconLocation = 'footer' ) : string
{
return '';
}
/**
* Used to add items to the user profile menu
*
* @param MemberClass $member Member whose profile is being viewed
* @return array<MenuItem>
*/
public function editProfileMenu( MemberClass $member ) : array
{
return [];
}
}
+108
View File
@@ -0,0 +1,108 @@
<?php
namespace IPS\Output\UI;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Helpers\Form\FormAbstract;
use IPS\Node\Model;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
abstract class Node
{
/**
* This needs to be declared in any child classes as well
*
* @var string|null
*/
public static ?string $class = NULL;
/**
* Can be used to add additional css classes to the node
*
* @param Model $node
* @return array
*/
public function css( Model $node ): array
{
return [];
}
/**
* Can be used to add additional data attributes to the node
*
* @param Model $node
* @return string
*/
public function dataAttributes( Model $node ): string
{
return '';
}
/**
* Can be used to add buttons to the ACP tree row
* and to the view page in the ACP
*
* @param Model $node
* @return array
*/
public function rowButtons( Model $node ): array
{
return [];
}
/**
* Returns additional HTML to be displayed in the ACP tree row
*
* @param Model $node
* @return string
*/
public function rowHtml( Model $node ) : string
{
return '';
}
/**
* Return a badge to be displayed in the ACP tree row
*
* @param Model $node
* @return null|array Null for no badge, or an array of badge data (0 => CSS class type, 1 => language string, 2 => optional raw HTML to show instead of language string)
*/
public function rowBadge( Model $node ) : array|null
{
return null;
}
/**
* Add elements to the Node form
* This method returns all elements that will be added.
* By default, all elements will be added in order at the end of the form.
* To specify placement within the form, @see FormAbstract::setPosition().
*
* @param Model $node
* @return array<string,FormAbstract>
*/
public function formElements( Model $node ): array
{
return [];
}
/**
* Called after the Node form is saved
*
* @param Model $node
* @param array $values
* @return void
*/
public function formPostSave( Model $node, array $values ): void
{
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace IPS\Output\UI;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
abstract class Review extends Comment
{
}
+163
View File
@@ -0,0 +1,163 @@
<?php
namespace IPS\Output\UI;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Application;
use IPS\Content;
use IPS\Node\Model;
use IPS\Patterns\Singleton;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
class UiExtension extends Singleton
{
/**
* @brief Singleton Instances
* @note This needs to be declared in any child classes as well, only declaring here for editor code-complete/error-check functionality
*/
protected static ?Singleton $instance = NULL;
/**
* @var array
*/
protected static array $extensions = [];
/**
* Load all available extensions
*
* @param string $type
* @return void
*/
protected function loadExtensions( string $type ) : void
{
if( !isset( static::$extensions[ $type ] ) )
{
static::$extensions[ $type ] = [];
foreach ( Application::allExtensions( 'core', 'UI' . $type, FALSE, 'core' ) as $key => $extension )
{
static::$extensions[$type][ $key ] = $extension;
}
}
}
/**
* Load extensions for this type
*
* @param string $type
* @return array
*/
protected function extensions( string $type ) : array
{
static::loadExtensions( $type );
return static::$extensions[ $type ];
}
/**
* Checks all UI extensions to verify that the classes are supported
* Return a list of all unsupported classes, or NULL if all classes are valid
*
* @param Application $application
* @return array|null
*/
public static function unsupportedExtensions( Application $application ) : ?array
{
$return = [];
foreach( $application->extensions( 'core', 'UINode', false ) as $ext )
{
/* @var Model $nodeClass */
$nodeClass = $ext::$class ?? null;
if( $nodeClass AND !$nodeClass::$canBeExtended )
{
$return[] = $nodeClass;
}
}
return count( $return ) ? $return : null;
}
/**
* Run a UI extension method
*
* @param Content|Model|string $object
* @param string $method
* @param array|null $payload
* @return array
*/
public function run( Content|Model|string $object, string $method, ?array $payload=array() ) : array
{
$className = is_string( $object ) ? $object : get_class( $object );
$baseClass = null;
switch( $className )
{
case '':
default:
return [];
case is_subclass_of( $className, Model::class ):
/* If this node class cannot be extended, just return and do nothing */
if( !$className::$canBeExtended )
{
return [];
}
$type = 'Node';
$baseClass = Model::class;
break;
case is_subclass_of( $className, Content\Item::class ):
$type = 'Item';
$baseClass = Content\Item::class;
break;
case is_subclass_of( $className, Content\Review::class ):
$type = 'Review';
$baseClass = Content\Review::class;
break;
case is_subclass_of( $className, Content\Comment::class ):
$type = 'Comment';
$baseClass = Content\Comment::class;
break;
}
$return = [];
/* If we are working with an object (Item/Comment/Node), put it first in the parameter list */
$params = is_array( $payload ) ? array_values( $payload ) : array();
array_unshift( $params, is_string( $object ) ? null : $object );
foreach( $this->extensions( $type ) as $extension )
{
/* Use subclass to account for classes in Pages */
if( isset( $extension::$class ) AND $className != $extension::$class AND !is_subclass_of( $className, $extension::$class ) )
{
continue;
}
/* Block extension of base classes */
if( $baseClass !== null AND $extension::$class == $baseClass )
{
continue;
}
if( $response = $extension->$method( ...$params ) )
{
if( is_array( $response ) )
{
$return = array_merge( $return, $response );
}
else
{
$return[] = $response;
}
}
}
return $return;
}
}