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,73 +12,133 @@
|
||||
namespace IPS\core;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function explode;
|
||||
use function get_called_class;
|
||||
use function intval;
|
||||
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
|
||||
*/
|
||||
class _FrontNavigation
|
||||
class FrontNavigation
|
||||
{
|
||||
/**
|
||||
* @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 $instance = NULL;
|
||||
protected static ?FrontNavigation $instance = NULL;
|
||||
|
||||
/**
|
||||
* @brief This is a hacky flag to indicate if active page is a club area so we know which tab to highlight in the menu
|
||||
*/
|
||||
public static $clubTabActive = FALSE;
|
||||
public static bool $clubTabActive = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Store root objects for re-use later
|
||||
*/
|
||||
protected $roots = NULL;
|
||||
protected ?array $roots = NULL;
|
||||
|
||||
/**
|
||||
* @brief Store subBars objects for later use
|
||||
*/
|
||||
protected $subBars = NULL;
|
||||
protected ?array $subBars = NULL;
|
||||
|
||||
/**
|
||||
* Get instance
|
||||
*
|
||||
* @return static
|
||||
* @return static|null
|
||||
*/
|
||||
public static function i()
|
||||
public static function i() : static|null
|
||||
{
|
||||
if( static::$instance === NULL )
|
||||
{
|
||||
$classname = \get_called_class();
|
||||
$classname = get_called_class();
|
||||
static::$instance = new $classname;
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check to see if a single node extension is currently active, so we can choose to not duplicate highlighted tabs
|
||||
*
|
||||
* @param string $appKey
|
||||
* @return bool
|
||||
*/
|
||||
public static function nodeExtensionIsActive( string $appKey ): bool
|
||||
{
|
||||
/* Checks to see if we have any single node extensions enabled, and if it is active so we don't duplicate tabs */
|
||||
foreach( static::frontNavigation() as $parent => $items )
|
||||
{
|
||||
foreach( $items as $item )
|
||||
{
|
||||
if ( $item['app'] === 'core' and $item['extension'] === 'Node' )
|
||||
{
|
||||
$config = json_decode( $item['config'], TRUE );
|
||||
|
||||
if ( isset( $config['nodeClass'] ) )
|
||||
{
|
||||
$bits = explode( '\\', $config['nodeClass'] );
|
||||
|
||||
if ( $bits[1] === $appKey )
|
||||
{
|
||||
/* It is a call to load a Node, but it should be cached from the navigation extension doing that already */
|
||||
try
|
||||
{
|
||||
$class = $config['nodeClass'];
|
||||
$node = $class::load( $config['id'] );
|
||||
if ( stristr( (string) Request::i()->url(), (string) $node->url() ) )
|
||||
{
|
||||
/* return true here.. or let it go around the foreach again for a check on another item */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch( OutOfRangeException ) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data store
|
||||
*
|
||||
* @param bool $noStore If true, will skip datastore and get from DB (used for ACP preview)
|
||||
* @return array
|
||||
*/
|
||||
public static function frontNavigation( $noStore=FALSE )
|
||||
public static function frontNavigation( bool $noStore=FALSE ) : array
|
||||
{
|
||||
if ( $noStore or !isset( \IPS\Data\Store::i()->frontNavigation ) )
|
||||
if ( $noStore or !isset( Store::i()->frontNavigation ) )
|
||||
{
|
||||
$frontNavigation = array( 0 => array(), 1 => array() );
|
||||
$select = \IPS\Db::i()->select( '*', 'core_menu', NULL, 'position' );
|
||||
if ( \count( $select ) )
|
||||
$select = Db::i()->select( '*', 'core_menu', NULL, 'position' );
|
||||
if ( count( $select ) )
|
||||
{
|
||||
foreach ( $select as $item )
|
||||
{
|
||||
if ( \IPS\Application::appIsEnabled( $item['app'] ) )
|
||||
if ( Application::appIsEnabled( $item['app'] ) )
|
||||
{
|
||||
$frontNavigation[ \intval( $item['parent'] ) ][ $item['id'] ] = $item;
|
||||
$frontNavigation[ intval( $item['parent'] ) ][ $item['id'] ] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,20 +146,20 @@ class _FrontNavigation
|
||||
{
|
||||
return $frontNavigation;
|
||||
}
|
||||
\IPS\Data\Store::i()->frontNavigation = $frontNavigation;
|
||||
Store::i()->frontNavigation = $frontNavigation;
|
||||
}
|
||||
return \IPS\Data\Store::i()->frontNavigation;
|
||||
return Store::i()->frontNavigation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete front navigation items by application
|
||||
*
|
||||
* @param \IPS\Application $app Application deleted
|
||||
* @param Application $app Application deleted
|
||||
* @return void
|
||||
*/
|
||||
public static function deleteByApplication( \IPS\Application $app )
|
||||
public static function deleteByApplication( Application $app ) : void
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_menu', array( array( 'extension=?', 'CustomItem' ) ) ) as $row )
|
||||
foreach( Db::i()->select( '*', 'core_menu', array( array( 'extension=?', 'CustomItem' ) ) ) as $row )
|
||||
{
|
||||
$config = json_decode( $row['config'], TRUE );
|
||||
|
||||
@@ -111,91 +171,98 @@ class _FrontNavigation
|
||||
|
||||
if ( ! empty( $data['app'] ) and $data['app'] === $app->directory )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_menu', array( 'id=?', $row['id'] ) );
|
||||
Db::i()->delete( 'core_menu', array( 'id=?', $row['id'] ) );
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_menu', array( 'app=?', $app->directory ) );
|
||||
Db::i()->delete( 'core_menu', array( 'app=?', $app->directory ) );
|
||||
|
||||
unset( \IPS\Data\Store::i()->frontNavigation );
|
||||
unset( Store::i()->frontNavigation );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build default front navigation
|
||||
*
|
||||
* @param bool $newInstall
|
||||
* @return void
|
||||
*/
|
||||
public static function buildDefaultFrontNavigation()
|
||||
public static function buildDefaultFrontNavigation( bool $newInstall=false ) : void
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_menu' );
|
||||
Db::i()->delete( 'core_menu' );
|
||||
|
||||
$position = 1;
|
||||
|
||||
/* Browse */
|
||||
\IPS\Db::i()->insert( 'core_menu', array(
|
||||
Db::i()->insert( 'core_menu', array(
|
||||
'id' => 1,
|
||||
'app' => 'core',
|
||||
'extension' => 'CustomItem',
|
||||
'config' => json_encode( array( 'menu_custom_item_url' => '', 'internal' => '' ) ),
|
||||
'extension' => 'Menu',
|
||||
'config' => '[]',
|
||||
'position' => $position++,
|
||||
'parent' => NULL,
|
||||
'permissions' => NULL,
|
||||
) );
|
||||
\IPS\Lang::saveCustom( 'core', "menu_item_1", \IPS\Member::loggedIn()->language()->get('default_menu_item_1') );
|
||||
Lang::saveCustom( 'core', "menu_item_1", Member::loggedIn()->language()->get('default_menu_item_1') );
|
||||
|
||||
/* Activity */
|
||||
\IPS\Db::i()->insert( 'core_menu', array(
|
||||
Db::i()->insert( 'core_menu', array(
|
||||
'id' => 2,
|
||||
'app' => 'core',
|
||||
'extension' => 'CustomItem',
|
||||
'config' => json_encode( array( 'menu_custom_item_url' => 'app=core&module=discover&controller=streams', 'internal' => 'discover_all' ) ),
|
||||
'extension' => 'Menu',
|
||||
'config' => '[]',
|
||||
'position' => $position++,
|
||||
'parent' => NULL,
|
||||
'permissions' => NULL,
|
||||
) );
|
||||
\IPS\Lang::saveCustom( 'core', "menu_item_2", \IPS\Member::loggedIn()->language()->get('default_menu_item_2') );
|
||||
Lang::saveCustom( 'core', "menu_item_2", Member::loggedIn()->language()->get('default_menu_item_2') );
|
||||
|
||||
/* Loop */
|
||||
$waiting = array();
|
||||
foreach ( \IPS\Application::applications() as $app )
|
||||
foreach ( Application::applications() as $app )
|
||||
{
|
||||
if ( \IPS\Application::appIsEnabled( $app->directory ) )
|
||||
/* When we're installing (dispatcher: setup) appIsEnabled() returns false */
|
||||
if( ! $newInstall )
|
||||
{
|
||||
$defaultNavigation = $app->defaultFrontNavigation();
|
||||
foreach ( $defaultNavigation as $type => $tabs )
|
||||
if ( !Application::appIsEnabled( $app->directory ) )
|
||||
{
|
||||
foreach ( $tabs as $config )
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$defaultNavigation = $app->defaultFrontNavigation();
|
||||
foreach ( $defaultNavigation as $type => $tabs )
|
||||
{
|
||||
foreach ( $tabs as $config )
|
||||
{
|
||||
switch ( $type )
|
||||
{
|
||||
switch ( $type )
|
||||
{
|
||||
case 'rootTabs':
|
||||
$parent = NULL;
|
||||
break;
|
||||
case 'browseTabs':
|
||||
$parent = 1;
|
||||
break;
|
||||
case 'activityTabs':
|
||||
$parent = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
$config['real_app'] = $app->directory;
|
||||
if ( !isset( $config['app'] ) )
|
||||
{
|
||||
$config['app'] = $app->directory;
|
||||
}
|
||||
|
||||
if ( $type == 'browseTabsEnd' )
|
||||
{
|
||||
$waiting[] = $config;
|
||||
}
|
||||
else
|
||||
{
|
||||
static::insertMenuItem( $parent, $config, $position );
|
||||
}
|
||||
case 'rootTabs':
|
||||
$parent = NULL;
|
||||
break;
|
||||
case 'browseTabs':
|
||||
$parent = 1;
|
||||
break;
|
||||
case 'activityTabs':
|
||||
$parent = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
$config['real_app'] = $app->directory;
|
||||
if ( !isset( $config['app'] ) )
|
||||
{
|
||||
$config['app'] = $app->directory;
|
||||
}
|
||||
|
||||
if ( $type == 'browseTabsEnd' )
|
||||
{
|
||||
$waiting[] = $config;
|
||||
}
|
||||
else
|
||||
{
|
||||
static::insertMenuItem( $parent ?? null, $config, $position );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,27 +276,27 @@ class _FrontNavigation
|
||||
/**
|
||||
* Insert a menu item
|
||||
*
|
||||
* @param int $parent Parent ID
|
||||
* @param int|null $parent Parent ID
|
||||
* @param array $config Configuration
|
||||
* @param int $position Position
|
||||
* @param bool $isMenuChild Is item in a menu?
|
||||
* @return void
|
||||
*/
|
||||
public static function insertMenuItem( $parent, $config, $position, $isMenuChild=FALSE )
|
||||
public static function insertMenuItem( ?int $parent, array $config, int $position, bool $isMenuChild=FALSE ) : void
|
||||
{
|
||||
$insertedId = \IPS\Db::i()->insert( 'core_menu', array(
|
||||
$insertedId = Db::i()->insert( 'core_menu', array(
|
||||
'app' => $config['app'],
|
||||
'extension' => $config['key'],
|
||||
'config' => json_encode( isset( $config['config'] ) ? $config['config'] : array() ),
|
||||
'position' => ( \intval( $position ) + 1 ),
|
||||
'parent' => $parent,
|
||||
'config' => json_encode( $config['config'] ?? array() ),
|
||||
'position' => ( $position + 1 ),
|
||||
'parent' => (int) $parent,
|
||||
'permissions' => NULL,
|
||||
'is_menu_child' => $isMenuChild,
|
||||
) );
|
||||
|
||||
if ( isset( $config['title'] ) )
|
||||
{
|
||||
\IPS\Lang::copyCustom( $config['real_app'], $config['title'], "menu_item_{$insertedId}" );
|
||||
Lang::copyCustom( $config['real_app'], $config['title'], "menu_item_{$insertedId}" );
|
||||
}
|
||||
|
||||
if ( isset( $config['children'] ) )
|
||||
@@ -250,7 +317,7 @@ class _FrontNavigation
|
||||
/**
|
||||
* @brief The active primary navigation bar
|
||||
*/
|
||||
public $activePrimaryNavBar = NULL;
|
||||
public ?int $activePrimaryNavBar = NULL;
|
||||
|
||||
/**
|
||||
* Get roots
|
||||
@@ -258,7 +325,7 @@ class _FrontNavigation
|
||||
* @param bool $noStore If true, will skip datastore and get from DB (used for ACP preview)
|
||||
* @return array
|
||||
*/
|
||||
public function roots( $noStore=FALSE )
|
||||
public function roots( bool $noStore=FALSE ) : array
|
||||
{
|
||||
if ( $this->roots === NULL )
|
||||
{
|
||||
@@ -270,7 +337,7 @@ class _FrontNavigation
|
||||
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
|
||||
if ( class_exists( $class ) )
|
||||
{
|
||||
$object = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'] );
|
||||
$object = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'], $item['menu_types'], json_decode( (string) $item['icon'], TRUE ), $item['parent'] );
|
||||
if ( !$this->activePrimaryNavBar )
|
||||
{
|
||||
$this->activePrimaryNavBar = $item['id'];
|
||||
@@ -289,7 +356,7 @@ class _FrontNavigation
|
||||
* @param bool $noStore If true, will skip datastore and get from DB (used for ACP preview)
|
||||
* @return array
|
||||
*/
|
||||
public function subBars( $noStore=FALSE )
|
||||
public function subBars( bool $noStore=FALSE ) : array
|
||||
{
|
||||
if ( $this->subBars === NULL )
|
||||
{
|
||||
@@ -309,13 +376,10 @@ class _FrontNavigation
|
||||
{
|
||||
foreach ( $frontNavigation[$i] as $item )
|
||||
{
|
||||
if ( empty( $item['is_menu_child'] ) )
|
||||
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
|
||||
if ( class_exists( $class ) )
|
||||
{
|
||||
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
|
||||
if ( class_exists( $class ) )
|
||||
{
|
||||
$this->subBars[ $item['parent'] ][ $item['id'] ] = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'] );
|
||||
}
|
||||
$this->subBars[ $item['parent'] ][ $item['id'] ] = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'], $item['menu_types'], json_decode( (string) $item['icon'], TRUE ), $item['parent'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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