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'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user