Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -2,9 +2,9 @@
/**
* @brief Front Navigation Handler
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Core
* @since 30 Jun 2015
* @version SVN_VERSION_NUMBER
@@ -29,7 +29,17 @@ class _FrontNavigation
* @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;
/**
* @brief Store root objects for re-use later
*/
protected $roots = NULL;
/**
* @brief Store subBars objects for later use
*/
protected $subBars = NULL;
/**
* Get instance
*
@@ -98,7 +108,7 @@ class _FrontNavigation
{
try
{
$data = \IPS\Http\Url::internal( $config['menu_custom_item_url'], NULL, $config['internal'] )->getFriendlyUrlData();
parse_str( $config['menu_custom_item_url'], $data );
if ( ! empty( $data['app'] ) and $data['app'] === $app->directory )
{
@@ -113,7 +123,7 @@ class _FrontNavigation
unset( \IPS\Data\Store::i()->frontNavigation );
}
/**
* Build default front navigation
*
@@ -123,17 +133,17 @@ class _FrontNavigation
{
\IPS\Db::i()->delete( 'core_menu' );
$topLevelPosition = 1;
$position = 1;
/* Browse */
\IPS\Db::i()->insert( 'core_menu', array(
'id' => 1,
'app' => 'core',
'extension' => 'CustomItem',
'config' => json_encode( array( 'menu_custom_item_url' => '', 'internal' => '' ) ),
'position' => $topLevelPosition++,
'position' => $position++,
'parent' => NULL,
'permissions' => '*',
'permissions' => NULL,
) );
/* Activity */
@@ -142,206 +152,96 @@ class _FrontNavigation
'app' => 'core',
'extension' => 'CustomItem',
'config' => json_encode( array( 'menu_custom_item_url' => 'app=core&module=discover&controller=streams', 'internal' => 'discover_all' ) ),
'position' => $topLevelPosition++,
'position' => $position++,
'parent' => NULL,
'permissions' => '*',
) );
/* Commerce requires a bit of a special set up */
if ( \IPS\Application::appIsEnabled('nexus') )
'permissions' => NULL,
) );
/* Loop */
$waiting = array();
foreach ( \IPS\Application::applications() as $app )
{
/* Store */
\IPS\Db::i()->insert( 'core_menu', array(
'id' => 4,
'app' => 'nexus',
'extension' => 'Store',
'config' => json_encode( array() ),
'position' => $topLevelPosition++,
'parent' => NULL,
'permissions' => '*',
) );
/* Support */
\IPS\Db::i()->insert( 'core_menu', array(
'id' => 5,
'app' => 'core',
'extension' => 'CustomItem',
'config' => json_encode( array( 'menu_custom_item_url' => 'app=nexus&module=support&controller=home', 'internal' => 'support' ) ),
'position' => $topLevelPosition++,
'parent' => NULL,
'permissions' => '*',
) );
/* My Details */
\IPS\Db::i()->insert( 'core_menu', array(
'id' => 6,
'app' => 'core',
'extension' => 'Menu',
'config' => json_encode( array() ),
'position' => 5,
'parent' => 4,
'permissions' => '*',
) );
}
/* Browse subitems */
$communityApps = array( 'forums', 'gallery', 'downloads', 'cms', 'blog', 'calendar', 'chat' );
$browsePosition = 1;
$toInsert = array();
foreach ( $communityApps as $app )
{
if ( \IPS\Application::appIsEnabled( $app ) )
if ( \IPS\Application::appIsEnabled( $app->directory ) )
{
foreach ( array_keys( \IPS\Application::load( $app )->extensions( 'core', 'FrontNavigation', FALSE ) ) as $key )
$defaultNavigation = $app->defaultFrontNavigation();
foreach ( $defaultNavigation as $type => $tabs )
{
$config = array();
if ( $app === 'cms' and $key === 'Cms' )
foreach ( $tabs as $config )
{
/* Cms.php was added to prevent upgrades breaking */
continue;
}
if ( $app === 'cms' and $key === 'Pages' )
{
try
switch ( $type )
{
$defaultPage = \IPS\cms\Pages\Page::getDefaultPage();
$config = array( 'menu_content_page' => $defaultPage->id, 'menu_title_page_type' => 0 );
case 'rootTabs':
$parent = NULL;
break;
case 'browseTabs':
$parent = 1;
break;
case 'activityTabs':
$parent = 2;
break;
}
catch( \OutOfRangeException $ex )
$config['real_app'] = $app->directory;
if ( !isset( $config['app'] ) )
{
continue;
$config['app'] = $app->directory;
}
if ( $type == 'browseTabsEnd' )
{
$waiting[] = $config;
}
else
{
static::insertMenuItem( $parent, $config, $position );
}
}
$toInsert[] = array(
'app' => $app,
'extension' => $key,
'config' => json_encode( $config ),
'position' => $browsePosition++,
'parent' => 1,
'permissions' => '',
);
}
}
}
/* Insert Apps */
\IPS\Db::i()->insert( 'core_menu', $toInsert );
/* Other 'browse' items */
foreach ( array( 'Guidelines', 'StaffDirectory', 'OnlineUsers' ) as $k )
foreach ( $waiting as $config )
{
\IPS\Db::i()->insert( 'core_menu', array(
'app' => 'core',
'extension' => $k,
'config' => json_encode( array() ),
'position' => $browsePosition++,
'parent' => 1,
'permissions' => '',
) );
static::insertMenuItem( 1, $config, $position );
}
}
/**
* Insert a menu item
*
* @param int $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 )
{
$insertedId = \IPS\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,
'permissions' => NULL,
'is_menu_child' => $isMenuChild,
) );
if ( isset( $config['title'] ) )
{
\IPS\Lang::copyCustom( $config['real_app'], $config['title'], "menu_item_{$insertedId}" );
}
/* Activity Subitems */
$activityPosition = 1;
foreach ( array( 'AllActivity', 'YourActivityStreams' ) as $k )
if ( isset( $config['children'] ) )
{
\IPS\Db::i()->insert( 'core_menu', array(
'app' => 'core',
'extension' => $k,
'config' => json_encode( array() ),
'position' => $activityPosition++,
'parent' => 2,
'permissions' => '',
) );
}
foreach ( array( 1, 2 ) as $k )
{
try
foreach ( $config['children'] as $childConfig )
{
\IPS\core\Stream::load( $k );
\IPS\Db::i()->insert( 'core_menu', array(
'app' => 'core',
'extension' => 'YourActivityStreamsItem',
'config' => json_encode( array( 'menu_stream_id' => $k ) ),
'position' => $activityPosition++,
'parent' => 2,
'permissions' => '',
) );
}
catch ( \Exception $e ) { }
}
foreach ( array( 'Search' ) as $k )
{
\IPS\Db::i()->insert( 'core_menu', array(
'app' => 'core',
'extension' => $k,
'config' => json_encode( array() ),
'position' => $activityPosition++,
'parent' => 2,
'permissions' => '',
) );
}
/* Commerce requires a bit of a special set up */
if ( \IPS\Application::appIsEnabled('nexus') )
{
$storePosition = 1;
foreach ( array( 'Donations', 'Orders', 'Purchases' ) as $k )
{
\IPS\Db::i()->insert( 'core_menu', array(
'app' => 'nexus',
'extension' => $k,
'config' => json_encode( array() ),
'position' => $storePosition++,
'parent' => 4,
'permissions' => '',
) );
}
$myDetailsPosition = 1;
foreach ( array( 'Info', 'Addresses', 'Cards', 'Credit', 'Alternatives', 'Referrals' ) as $k )
{
\IPS\Db::i()->insert( 'core_menu', array(
'app' => 'nexus',
'extension' => $k,
'config' => json_encode( array() ),
'position' => $myDetailsPosition++,
'parent' => 6,
'permissions' => '',
) );
}
$supportPosition = 1;
foreach ( array( 'Support', 'NetworkStatus' ) as $k )
{
\IPS\Db::i()->insert( 'core_menu', array(
'app' => 'nexus',
'extension' => $k,
'config' => json_encode( array() ),
'position' => $supportPosition++,
'parent' => 5,
'permissions' => '',
) );
}
}
/* Other apps */
$toGiveToParents = array();
$parentIds = array();
foreach ( \IPS\Application::allExtensions( 'core', 'FrontNavigation', FALSE, NULL, NULL, FALSE ) as $key => $class )
{
$exploded = explode( '_', $key );
if ( !in_array( $exploded[0], array_merge( $communityApps, array( 'core', 'nexus' ) ) ) )
{
$parentIds[ $exploded[0] ][ $exploded[1] ] = \IPS\Db::i()->insert( 'core_menu', array(
'app' => $exploded[0],
'extension' => $exploded[1],
'config' => json_encode( array() ),
'position' => $topLevelPosition++,
'parent' => NULL,
'permissions' => '',
) );
$childConfig['real_app'] = $config['real_app'];
if ( !isset( $childConfig['app'] ) )
{
$childConfig['app'] = $config['real_app'];
}
static::insertMenuItem( $insertedId, $childConfig, $position, $config['app'] == 'core' and $config['key'] == 'Menu' );
}
}
}
@@ -359,21 +259,26 @@ class _FrontNavigation
*/
public function roots( $noStore=FALSE )
{
$frontNavigation = static::frontNavigation( $noStore );
$return = array();
foreach ( $frontNavigation[0] as $item )
if ( $this->roots === NULL )
{
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
$object = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'] );
if ( !$this->activePrimaryNavBar )
$this->roots = array();
$frontNavigation = static::frontNavigation( $noStore );
$return = array();
foreach ( $frontNavigation[0] as $item )
{
$this->activePrimaryNavBar = $item['id'];
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
$object = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'] );
if ( !$this->activePrimaryNavBar )
{
$this->activePrimaryNavBar = $item['id'];
}
$this->roots[ $item['id'] ] = $object;
}
$return[ $item['id'] ] = $object;
}
return $return;
}
return $this->roots;
}
/**
* Get sub-bars
*
@@ -382,27 +287,37 @@ class _FrontNavigation
*/
public function subBars( $noStore=FALSE )
{
$frontNavigation = static::frontNavigation( $noStore );
$return = array();
$parentIDs = array();
// Changed so that empty sub bars don't add an array to their parent, allowing us to do count( $subBars ) and figure
// out if there's any to show.
foreach ( $frontNavigation[0] as $item )
if ( $this->subBars === NULL )
{
$parentIDs[] = $item['id'];
}
foreach ( $parentIDs as $i )
{
if ( isset( $frontNavigation[$i] ) )
$this->subBars = array();
$frontNavigation = static::frontNavigation( $noStore );
$parentIDs = array();
// Changed so that empty sub bars don't add an array to their parent, allowing us to do count( $subBars ) and figure
// out if there's any to show.
foreach ( $frontNavigation[0] as $item )
{
foreach ( $frontNavigation[$i] as $item )
$parentIDs[] = $item['id'];
}
foreach ( $parentIDs as $i )
{
if ( isset( $frontNavigation[$i] ) )
{
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
$return[ $item['parent'] ][ $item['id'] ] = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'] );
foreach ( $frontNavigation[$i] as $item )
{
if ( empty( $item['is_menu_child'] ) )
{
$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'] );
}
}
}
}
}
}
return $return;
return $this->subBars;
}
}
@@ -2,9 +2,9 @@
/**
* @brief Abstract Front Navigation Extension
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Core
* @since 30 Jun 2015
* @version SVN_VERSION_NUMBER
@@ -24,11 +24,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
abstract class _FrontNavigationAbstract
{
const DEFAULT_LOCATION_ROOT = NULL;
const DEFAULT_LOCATION_BROWSE = 1;
const DEFAULT_LOCATION_ACTIVITY = 2;
const DEFAULT_LOCATION_MORE = 3;
/**
* @brief Store sub item objects for re-use later
*/
protected $subItems = NULL;
/**
* Get sub items of an item
*
@@ -36,27 +36,25 @@ abstract class _FrontNavigationAbstract
*/
public function subItems()
{
$frontNavigation = \IPS\core\FrontNavigation::frontNavigation();
$return = array();
if ( isset( $frontNavigation[ $this->id ] ) )
if ( $this->subItems === NULL )
{
foreach ( $frontNavigation[ $this->id ] as $item )
$this->subItems = array();
$frontNavigation = \IPS\core\FrontNavigation::frontNavigation();
if ( isset( $frontNavigation[ $this->id ] ) )
{
$class = 'IPS\\' . $item['app'] . '\extensions\core\FrontNavigation\\' . $item['extension'];
$return[ $item['id'] ] = new $class( json_decode( $item['config'], TRUE ), $item['id'], $item['permissions'] );
foreach ( $frontNavigation[ $this->id ] as $item )
{
$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'] );
}
}
}
}
return $return;
}
/**
* Default Location
*
* @return string
*/
public static function defaultLocation()
{
return static::DEFAULT_LOCATION_BROWSE;
return $this->subItems;
}
/**
@@ -133,19 +131,48 @@ abstract class _FrontNavigationAbstract
}
/**
* Can access?
* Can this item be used at all?
* For example, if this will link to a particular feature which has been diabled, it should
* not be available, even if the user has permission
*
* @return bool
*/
public static function isEnabled()
{
return TRUE;
}
/**
* Can the currently logged in user access the content this item links to?
*
* @return bool
*/
public function canAccessContent()
{
return TRUE;
}
/**
* Can the currently logged in user see this menu item?
*
* @return bool
*/
public function canView()
{
if ( $this->permissions and $this->permissions != '*' )
if ( static::isEnabled() )
{
return \IPS\Member::loggedIn()->inGroup( explode( ',', $this->permissions ) );
if ( $this->permissions === NULL ) // NULL indicates "Show this item to users who can access its content."
{
return $this->canAccessContent();
}
else
{
return $this->permissions == '*' ? TRUE : \IPS\Member::loggedIn()->inGroup( explode( ',', $this->permissions ) );
}
}
return TRUE;
return FALSE;
}
/**
* Get Title
*
@@ -169,7 +196,7 @@ abstract class _FrontNavigationAbstract
{
return '';
}
/**
* Is Active?
*
@@ -177,6 +204,21 @@ abstract class _FrontNavigationAbstract
*/
public function active()
{
return FALSE;
}
/**
* Is this item, or any of it's child items, active?
*
* @return bool
*/
public function activeOrChildActive()
{
if ( $this->active() )
{
return TRUE;
}
foreach ( $this->subItems() as $item )
{
if ( $item->active() )
@@ -191,9 +233,10 @@ abstract class _FrontNavigationAbstract
/**
* Children
*
* @param bool $noStore If true, will skip datastore and get from DB (used for ACP preview)
* @return array
*/
public function children()
public function children( $noStore=FALSE )
{
return NULL;
}