Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,33 +12,48 @@
|
||||
namespace IPS\core\FrontNavigation;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\core\FrontNavigation;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function json_decode;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Front Navigation Extension: Custom Item
|
||||
*/
|
||||
abstract class _FrontNavigationAbstract
|
||||
abstract class FrontNavigationAbstract
|
||||
{
|
||||
/**
|
||||
* @var string Default icon
|
||||
*/
|
||||
public string $defaultIcon;
|
||||
|
||||
/**
|
||||
* @brief Store sub item objects for re-use later
|
||||
*/
|
||||
protected $subItems = NULL;
|
||||
protected ?array $subItems = NULL;
|
||||
|
||||
/**
|
||||
* Get sub items of an item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function subItems()
|
||||
public function subItems() : array
|
||||
{
|
||||
if ( $this->subItems === NULL )
|
||||
{
|
||||
$this->subItems = array();
|
||||
$frontNavigation = \IPS\core\FrontNavigation::frontNavigation();
|
||||
$frontNavigation = FrontNavigation::frontNavigation();
|
||||
|
||||
if ( isset( $frontNavigation[ $this->id ] ) )
|
||||
{
|
||||
@@ -47,7 +62,7 @@ abstract class _FrontNavigationAbstract
|
||||
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
|
||||
if ( class_exists( $class ) )
|
||||
{
|
||||
$this->subItems[ $item['id'] ] = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'] );
|
||||
$this->subItems[ $item['id'] ] = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'], $item['menu_types'], json_decode( (string) $item['icon'], TRUE ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,13 +70,61 @@ abstract class _FrontNavigationAbstract
|
||||
|
||||
return $this->subItems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the icon data for the attribute
|
||||
* @return string
|
||||
*/
|
||||
public function getIconDataForAttribute(): string
|
||||
{
|
||||
if ( $this->icon and ! empty( $this->icon ) and is_array( $this->icon ) )
|
||||
{
|
||||
/* This is from the icon picker, so let's format a bit */
|
||||
$icon = $this->icon[0];
|
||||
|
||||
if ( $icon['type'] === 'emoji' )
|
||||
{
|
||||
return $icon['raw'];
|
||||
}
|
||||
else if ( $icon['type'] === 'fa' )
|
||||
{
|
||||
return 'fa';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getDefaultIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the icon data for the attribute
|
||||
* @return string
|
||||
*/
|
||||
public function getIconData(): string
|
||||
{
|
||||
if ( !empty( $this->icon[0]['raw'] ) )
|
||||
{
|
||||
return $this->icon[0]['raw'];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default icon
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultIcon(): string
|
||||
{
|
||||
return ( $this->defaultIcon ?? '\f1c5' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow multiple instances?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function allowMultiple()
|
||||
public static function allowMultiple() : bool
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -70,10 +133,10 @@ abstract class _FrontNavigationAbstract
|
||||
* Get configuration fields
|
||||
*
|
||||
* @param array $existingConfiguration The existing configuration, if editing an existing item
|
||||
* @param int $id The ID number of the existing item, if editing
|
||||
* @param int|null $id The ID number of the existing item, if editing
|
||||
* @return array
|
||||
*/
|
||||
public static function configuration( $existingConfiguration, $id = NULL )
|
||||
public static function configuration( array $existingConfiguration, ?int $id = NULL ) : array
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@@ -85,7 +148,7 @@ abstract class _FrontNavigationAbstract
|
||||
* @param int $id The ID number of the existing item, if editing
|
||||
* @return array
|
||||
*/
|
||||
public static function parseConfiguration( $configuration, $id )
|
||||
public static function parseConfiguration( array $configuration, int $id ) : array
|
||||
{
|
||||
return $configuration;
|
||||
}
|
||||
@@ -93,31 +156,50 @@ abstract class _FrontNavigationAbstract
|
||||
/**
|
||||
* @brief The configuration
|
||||
*/
|
||||
protected $configuration;
|
||||
protected array $configuration = [];
|
||||
|
||||
/**
|
||||
* @brief The ID number
|
||||
*/
|
||||
public $id;
|
||||
public ?int $id = null;
|
||||
|
||||
/**
|
||||
* @brief The permissions
|
||||
*/
|
||||
public $permissions;
|
||||
|
||||
public array|string|null $permissions = null;
|
||||
|
||||
/**
|
||||
* @brief The menu types
|
||||
*/
|
||||
public string $menuTypes = '';
|
||||
|
||||
/**
|
||||
* @brief The icon data
|
||||
*/
|
||||
public array|null $icon = null;
|
||||
|
||||
/**
|
||||
* @brief Parent ID
|
||||
*/
|
||||
public int $parent = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $configuration The configuration
|
||||
* @param int $id The ID number
|
||||
* @param string $permissions The permissions (* or comma-delimited list of groups)
|
||||
* @param string|null $permissions The permissions (* or comma-delimited list of groups)
|
||||
* @param string $menuTypes The menu types (either * or json string)
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $configuration, $id, $permissions )
|
||||
public function __construct( array $configuration, int $id, string|null $permissions, string $menuTypes, array|null $icon, int|null $parent = 0 )
|
||||
{
|
||||
$this->configuration = $configuration;
|
||||
$this->id = $id;
|
||||
$this->permissions = $permissions;
|
||||
$this->menuTypes = $menuTypes;
|
||||
$this->icon = $icon;
|
||||
$this->parent = intval( $parent ); // Always make sure we have an integer, and not a null from the database
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +207,7 @@ abstract class _FrontNavigationAbstract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function permissionsCanInherit()
|
||||
public static function permissionsCanInherit() : bool
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -137,7 +219,7 @@ abstract class _FrontNavigationAbstract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEnabled()
|
||||
public static function isEnabled() : bool
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -147,7 +229,7 @@ abstract class _FrontNavigationAbstract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canAccessContent()
|
||||
public function canAccessContent() : bool
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -157,7 +239,7 @@ abstract class _FrontNavigationAbstract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canView()
|
||||
public function canView() : bool
|
||||
{
|
||||
if ( static::isEnabled() )
|
||||
{
|
||||
@@ -167,7 +249,7 @@ abstract class _FrontNavigationAbstract
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->permissions == '*' ? TRUE : \IPS\Member::loggedIn()->inGroup( explode( ',', $this->permissions ) );
|
||||
return $this->permissions == '*' ? TRUE : Member::loggedIn()->inGroup( explode( ',', $this->permissions ) );
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
@@ -178,21 +260,21 @@ abstract class _FrontNavigationAbstract
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function title();
|
||||
abstract public function title() : string;
|
||||
|
||||
/**
|
||||
* Get Link
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
* @return string|Url|null
|
||||
*/
|
||||
abstract public function link();
|
||||
abstract public function link() : Url|string|null;
|
||||
|
||||
/**
|
||||
* Get Attributes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function attributes()
|
||||
public function attributes() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@@ -202,7 +284,7 @@ abstract class _FrontNavigationAbstract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function active()
|
||||
public function active() : bool
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -212,7 +294,7 @@ abstract class _FrontNavigationAbstract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function activeOrChildActive()
|
||||
public function activeOrChildActive() : bool
|
||||
{
|
||||
if ( $this->active() )
|
||||
{
|
||||
@@ -234,10 +316,51 @@ abstract class _FrontNavigationAbstract
|
||||
* Children
|
||||
*
|
||||
* @param bool $noStore If true, will skip datastore and get from DB (used for ACP preview)
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function children( $noStore=FALSE )
|
||||
public function children( bool $noStore=FALSE ) : ?array
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this item available for the specified type?
|
||||
*
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public function isAvailableFor( string $type ): bool
|
||||
{
|
||||
if ( $this->menuTypes === '*' )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $json = json_decode( $this->menuTypes, true ) )
|
||||
{
|
||||
return in_array( $type, $json );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A super handy method to avoid lots of PHP code in templates
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSideBarItemCollapsed(): bool
|
||||
{
|
||||
if ( isset( Request::i()->cookie['collapsedNavigationPanels'] ) AND in_array( $this->id, json_decode( Request::i()->cookie['collapsedNavigationPanels'], true ) ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( ! isset( Request::i()->cookie['collapsedNavigationPanels'] ) )
|
||||
{
|
||||
/* By default, we just want to collapse the sub-items, not the top level items */
|
||||
return $this->parent > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user