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

@@ -11,100 +11,116 @@
namespace IPS\core\modules\admin\overview;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use IPS\Application;
use IPS\DateTime;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Http\Url;
use IPS\Member;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Theme;
use function defined;
use function in_array;
use function intval;
use function strpos;
use function substr;
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;
}
/**
* ACP Dashboard
*/
class _dashboard extends \IPS\Dispatcher\Controller
class dashboard extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Show the ACP dashboard
*
* @return void
*/
protected function manage()
protected function manage() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'view_dashboard' );
Dispatcher::i()->checkAcpPermission( 'view_dashboard' );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('admin_dashboard.js', 'core') );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/dashboard.css', 'core', 'admin' ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js('admin_dashboard.js', 'core') );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'system/dashboard.css', 'core', 'admin' ) );
/* Figure out which blocks we should show */
$toShow = $this->current( TRUE );
/* Now grab dashboard extensions */
$blocks = array();
$info = array();
foreach ( \IPS\Application::allExtensions( 'core', 'Dashboard', TRUE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'Dashboard', TRUE, 'core' ) as $key => $extension )
{
if ( !method_exists( $extension, 'canView' ) or $extension->canView() )
if ( $extension->canView() )
{
$info[ $key ] = array(
'name' => \IPS\Member::loggedIn()->language()->addToStack('block_' . $key ),
'name' => Member::loggedIn()->language()->addToStack('block_' . $key ),
'key' => $key,
'app' => \substr( $key, 0, \strpos( $key, '_' ) )
'app' => substr( $key, 0, strpos( $key, '_' ) )
);
if( method_exists( $extension, 'getBlock' ) )
foreach( $toShow as $row )
{
foreach( $toShow as $row )
if( in_array( $key, $row ) )
{
if( \in_array( $key, $row ) )
{
$blocks[ $key ] = $extension->getBlock();
break;
}
$blocks[ $key ] = $extension->getBlock();
break;
}
}
}
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('dashboard');
\IPS\Output::i()->customHeader = \IPS\Theme::i()->getTemplate( 'dashboard' )->dashboardHeader( $info, $blocks );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'dashboard' )->dashboard( $toShow, $blocks, $info );
Output::i()->title = Member::loggedIn()->language()->addToStack('dashboard');
Output::i()->customHeader = Theme::i()->getTemplate( 'dashboard' )->dashboardHeader( $info, $blocks );
Output::i()->output = Theme::i()->getTemplate( 'dashboard' )->dashboard( $toShow, $blocks, $info );
}
/**
* Return a json-encoded array of the current blocks to show
*
* @param bool $return Flag to indicate if the array should be returned instead of output
* @return void
* @return array|null
*/
public function current( $return=FALSE )
public function current( bool $return=FALSE ) : ?array
{
if( \IPS\Settings::i()->acp_dashboard_blocks )
if( Settings::i()->acp_dashboard_blocks )
{
$blocks = json_decode( \IPS\Settings::i()->acp_dashboard_blocks, TRUE );
$blocks = json_decode( Settings::i()->acp_dashboard_blocks, TRUE );
}
else
{
$blocks = array();
}
$toShow = isset( $blocks[ \IPS\Member::loggedIn()->member_id ] ) ? $blocks[ \IPS\Member::loggedIn()->member_id ] : array();
$toShow = isset( $blocks[ Member::loggedIn()->member_id ] ) ? $blocks[ Member::loggedIn()->member_id ] : array();
if( !$toShow OR !isset( $toShow['main'] ) OR !isset( $toShow['side'] ) )
{
$toShow = array(
'main' => array( 'core_AdminNotes', 'core_Registrations', 'core_AwaitingValidation', 'core_BackgroundQueue' ),
'side' => array( 'core_OnlineAdmins', 'core_FailedLogins', 'core_OnlineUsers' ),
'main' => array( 'core_Registrations', 'core_BackgroundQueue' ),
'side' => array( 'core_AdminNotes', 'core_OnlineUsers' ),
'collapsed' => array( 'core_BackgroundQueue' ),
);
$blocks[ \IPS\Member::loggedIn()->member_id ] = $toShow;
$blocks[ Member::loggedIn()->member_id ] = $toShow;
\IPS\Settings::i()->changeValues( array( 'acp_dashboard_blocks' => json_encode( $blocks ) ) );
Settings::i()->changeValues( array( 'acp_dashboard_blocks' => json_encode( $blocks ) ) );
}
/* Upon initial upgrade to 4.3 the key won't exist, so apply to bg queue by default */
elseif( !array_key_exists( 'collapsed', $toShow ) )
@@ -117,7 +133,8 @@ class _dashboard extends \IPS\Dispatcher\Controller
return $toShow;
}
\IPS\Output::i()->output = json_encode( $toShow );
Output::i()->output = json_encode( $toShow );
return null;
}
/**
@@ -125,14 +142,14 @@ class _dashboard extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function getBlock()
public function getBlock() : void
{
$output = '';
/* Loop through the dashboard extensions in the specified application */
foreach( \IPS\Application::load( \IPS\Request::i()->appKey )->extensions( 'core', 'Dashboard', 'core' ) as $key => $_extension )
foreach( Application::load( Request::i()->appKey )->extensions( 'core', 'Dashboard', 'core' ) as $key => $_extension )
{
if( \IPS\Request::i()->appKey . '_' . $key == \IPS\Request::i()->blockKey )
if( Request::i()->appKey . '_' . $key == Request::i()->blockKey )
{
if( method_exists( $_extension, 'getBlock' ) )
{
@@ -143,7 +160,7 @@ class _dashboard extends \IPS\Dispatcher\Controller
}
}
\IPS\Output::i()->output = $output;
Output::i()->output = $output;
}
/**
@@ -152,20 +169,20 @@ class _dashboard extends \IPS\Dispatcher\Controller
* @return void
* @note When submitted via AJAX, the array should be json-encoded
*/
public function update()
public function update() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
if( \IPS\Settings::i()->acp_dashboard_blocks )
if( Settings::i()->acp_dashboard_blocks )
{
$blocks = json_decode( \IPS\Settings::i()->acp_dashboard_blocks, TRUE );
$blocks = json_decode( Settings::i()->acp_dashboard_blocks, TRUE );
}
else
{
$blocks = array();
}
$saveBlocks = \IPS\Request::i()->blocks;
$saveBlocks = Request::i()->blocks;
foreach( array( 'main', 'side', 'collapsed' ) as $saveKey )
{
@@ -175,17 +192,17 @@ class _dashboard extends \IPS\Dispatcher\Controller
}
}
$blocks[ \IPS\Member::loggedIn()->member_id ] = $saveBlocks;
$blocks[ Member::loggedIn()->member_id ] = $saveBlocks;
\IPS\Settings::i()->changeValues( array( 'acp_dashboard_blocks' => json_encode( $blocks ) ) );
Settings::i()->changeValues( array( 'acp_dashboard_blocks' => json_encode( $blocks ) ) );
if( \IPS\Request::i()->isAjax() )
if( Request::i()->isAjax() )
{
\IPS\Output::i()->output = 1;
Output::i()->output = 1;
return;
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=dashboard" ), 'saved' );
Output::i()->redirect( Url::internal( "app=core&module=overview&controller=dashboard" ), 'saved' );
}
/**
@@ -193,17 +210,17 @@ class _dashboard extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function switchSnooze()
public function switchSnooze() : void
{
$value = [ 'hits' => 1, 'lastClick' => time() ];
if ( isset( \IPS\Request::i()->cookie['acpLinkSnooze'] ) and $value = json_decode( \IPS\Request::i()->cookie['acpLinkSnooze'], true ) )
if ( isset( Request::i()->cookie['acpLinkSnooze'] ) and $value = json_decode( Request::i()->cookie['acpLinkSnooze'], true ) )
{
$value['hits'] = \intval( $value['hits'] ) + 1;
$value['hits'] = intval( $value['hits'] ) + 1;
$value['lastClick'] = time();
}
\IPS\Request::i()->setCookie( 'acpLinkSnooze', json_encode( $value ), ( new \IPS\DateTime )->add( new \DateInterval( 'P2Y' ) ) );
Request::i()->setCookie( 'acpLinkSnooze', json_encode( $value ), ( new DateTime )->add( new DateInterval( 'P2Y' ) ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=dashboard" ), 'The Switch to Cloud link won\'t show for a while' );
Output::i()->redirect( Url::internal( "app=core&module=overview&controller=dashboard" ), 'The Switch to Cloud link won\'t show for a while' );
}
}