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
+104
-111
@@ -11,103 +11,123 @@
|
||||
namespace IPS\Application;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Node\Permissions;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Node class for Modules
|
||||
*/
|
||||
class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
class Module extends Model implements Permissions
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_modules';
|
||||
public static ?string $databaseTable = 'core_modules';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'sys_module_';
|
||||
public static string $databasePrefix = 'sys_module_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array( 'sys_module_key' );
|
||||
protected static array $databaseIdFields = array( 'sys_module_key' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent Node ID Database Column
|
||||
*/
|
||||
public static $parentNodeColumnId = 'application';
|
||||
public static string $parentNodeColumnId = 'application';
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent Node Class
|
||||
*/
|
||||
public static $parentNodeClass = 'IPS\Application';
|
||||
public static string $parentNodeClass = 'IPS\Application';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'applications_and_modules';
|
||||
public static string $nodeTitle = 'applications_and_modules';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Enabled/Disabled Column
|
||||
*/
|
||||
public static $databaseColumnEnabledDisabled = 'visible';
|
||||
public static ?string $databaseColumnEnabledDisabled = 'visible';
|
||||
|
||||
/**
|
||||
* @brief [Node] App for permission index
|
||||
*/
|
||||
public static $permApp = 'core';
|
||||
public static ?string $permApp = 'core';
|
||||
|
||||
/**
|
||||
* @brief [Node] Type for permission index
|
||||
*/
|
||||
public static $permType = 'module';
|
||||
public static ?string $permType = 'module';
|
||||
|
||||
/**
|
||||
* @brief [Node] Prefix string that is automatically prepended to permission matrix language strings
|
||||
*/
|
||||
public static $permissionLangPrefix = 'module_';
|
||||
public static string $permissionLangPrefix = 'module_';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
*/
|
||||
protected static $restrictions = array( 'app' => 'core', 'module' => 'applications', 'all' => 'module_manage' );
|
||||
protected static ?array $restrictions = array( 'app' => 'core', 'module' => 'applications', 'all' => 'module_manage' );
|
||||
|
||||
/**
|
||||
* @brief [Node] Sortable?
|
||||
*/
|
||||
public static $nodeSortable = FALSE;
|
||||
public static bool $nodeSortable = FALSE;
|
||||
|
||||
/**
|
||||
* @brief All modules
|
||||
*/
|
||||
protected static $modules = NULL;
|
||||
|
||||
protected static ?array $modules = NULL;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public bool $_skipClearingMenuCache = false;
|
||||
|
||||
/**
|
||||
* Get Modules
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public static function modules()
|
||||
public static function modules(): array
|
||||
{
|
||||
if( static::$modules === NULL )
|
||||
{
|
||||
@@ -127,31 +147,31 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @return array
|
||||
* @note Note that all records are returned, even disabled report rules. Enable status needs to be checked in userland code when appropriate.
|
||||
*/
|
||||
public static function getStore()
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->modules ) )
|
||||
if ( !isset( Store::i()->modules ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->modules = iterator_to_array( \IPS\Db::i()->select( '*', 'core_modules', NULL, 'sys_module_position' )->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=core_modules.sys_module_id", 'core', 'module' ) ) );
|
||||
Store::i()->modules = iterator_to_array( Db::i()->select( '*', 'core_modules', NULL, 'sys_module_position' )->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=core_modules.sys_module_id", 'core', 'module' ) ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->modules;
|
||||
return Store::i()->modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a module
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $key
|
||||
* @param string|NULL $area
|
||||
* @return \IPS\Application\Module
|
||||
* @throws \OutOfRangeException
|
||||
* @param string $app
|
||||
* @param string $key
|
||||
* @param string|null $area
|
||||
* @return Module
|
||||
* @throws OutOfRangeException
|
||||
*/
|
||||
public static function get( $app, $key, $area=NULL )
|
||||
public static function get( string $app, string $key, string $area=NULL ): Module
|
||||
{
|
||||
$modules = static::modules();
|
||||
if ( isset( $modules[ $app ] ) )
|
||||
{
|
||||
$area = $area ?: \IPS\Dispatcher::i()->controllerLocation;
|
||||
$area = $area ?: Dispatcher::i()->controllerLocation;
|
||||
if ( isset( $modules[ $app ][ $area ] ) )
|
||||
{
|
||||
if ( isset( $modules[ $app ][ $area ][ $key ] ) )
|
||||
@@ -161,7 +181,7 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,14 +189,11 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAsDefault()
|
||||
public function setAsDefault() : void
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_modules', array( 'sys_module_default' => 0 ), array( 'sys_module_area=? AND sys_module_application=?', $this->area, $this->application ) );
|
||||
\IPS\Db::i()->update( 'core_modules', array( 'sys_module_default' => 1 ), array( 'sys_module_id=?', $this->id ) );
|
||||
unset( \IPS\Data\Store::i()->modules );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
Db::i()->update( 'core_modules', array( 'sys_module_default' => 0 ), array( 'sys_module_area=? AND sys_module_application=?', $this->area, $this->application ) );
|
||||
Db::i()->update( 'core_modules', array( 'sys_module_default' => 1 ), array( 'sys_module_id=?', $this->id ) );
|
||||
unset( Store::i()->modules );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,21 +205,21 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @param mixed $where Where clause
|
||||
* @return array
|
||||
*/
|
||||
public static function search( $column, $query, $order=NULL, $where=array() )
|
||||
public static function search( string $column, string $query, string $order=NULL, mixed $where=array() ): array
|
||||
{
|
||||
if ( $column === '_title' )
|
||||
{
|
||||
$return = array();
|
||||
foreach( \IPS\Member::loggedIn()->language()->words as $k => $v )
|
||||
foreach( Member::loggedIn()->language()->words as $k => $v )
|
||||
{
|
||||
if ( preg_match( '/^module__([a-z]*)_([a-z]*)$/', $k, $matches ) and mb_strpos( mb_strtolower( $v ), mb_strtolower( $query ) ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$module = static::load( $matches[2], 'sys_module_key', \count( $where ) ? array_merge( array( array( 'sys_module_application=? and sys_module_area=?', $matches[1], 'front' ) ), array( $where ) ) : array( array( 'sys_module_application=?', $matches[1] ) ) );
|
||||
$module = static::load( $matches[2], 'sys_module_key', count( $where ) ? array_merge( array( array( 'sys_module_application=? and sys_module_area=?', $matches[1], 'front' ) ), array( $where ) ) : array( array( 'sys_module_application=?', $matches[1] ) ) );
|
||||
$return[ $module->_id ] = $module;
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( OutOfRangeException $e ) { }
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
@@ -215,24 +232,24 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* Example code explains return value
|
||||
*
|
||||
* @code
|
||||
array(
|
||||
array(
|
||||
'icon' => array(
|
||||
'icon.png' // Path to icon
|
||||
'core' // Application icon belongs to
|
||||
),
|
||||
'title' => 'foo', // Language key to use for button's title parameter
|
||||
'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
),
|
||||
... // Additional buttons
|
||||
);
|
||||
* array(
|
||||
* array(
|
||||
* 'icon' => array(
|
||||
* 'icon.png' // Path to icon
|
||||
* 'core' // Application icon belongs to
|
||||
* ),
|
||||
* 'title' => 'foo', // Language key to use for button's title parameter
|
||||
* 'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
* 'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
* ),
|
||||
* ... // Additional buttons
|
||||
* );
|
||||
* @endcode
|
||||
* @param string $url Base URL
|
||||
* @param Url $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
public function getButtons( Url $url, bool $subnode=FALSE ):array
|
||||
{
|
||||
$buttons = array();
|
||||
|
||||
@@ -242,12 +259,12 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
'icon' => 'lock',
|
||||
'title' => 'permissions',
|
||||
'link' => "{$url}&do=permissions&id={$this->_id}" . ( $subnode ? '&subnode=1' : '' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('permissions') )
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('permissions') )
|
||||
);
|
||||
}
|
||||
|
||||
$buttons['default'] = array(
|
||||
'icon' => $this->default ? 'star' : 'star-o',
|
||||
'icon' => $this->default ? 'star' : 'regular fa-star',
|
||||
'title' => 'make_default_module',
|
||||
'link' => $url->csrf() . "&do=setDefaultModule&id={$this->_id}&default=1",
|
||||
);
|
||||
@@ -260,10 +277,10 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__title()
|
||||
protected function get__title(): string
|
||||
{
|
||||
$key = "module__{$this->application}_{$this->key}";
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( $key );
|
||||
return Member::loggedIn()->language()->addToStack( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,13 +288,13 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function titleForLog()
|
||||
public function titleForLog(): ?string
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( "module__{$this->application}_{$this->key}" );
|
||||
return Lang::load( Lang::defaultLanguage() )->get( "module__{$this->application}_{$this->key}" );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
return $this->_title;
|
||||
}
|
||||
@@ -288,7 +305,7 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__icon()
|
||||
protected function get__icon(): mixed
|
||||
{
|
||||
return 'cube';
|
||||
}
|
||||
@@ -299,7 +316,7 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__locked()
|
||||
protected function get__locked(): ?bool
|
||||
{
|
||||
return $this->protected;
|
||||
}
|
||||
@@ -310,7 +327,7 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @return bool
|
||||
* @note Modules don't really have "child nodes". Controllers are not addable via the ACP.
|
||||
*/
|
||||
public function canAdd()
|
||||
public function canAdd(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -320,7 +337,7 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canManagePermissions()
|
||||
public function canManagePermissions(): bool
|
||||
{
|
||||
if ( $this->protected )
|
||||
{
|
||||
@@ -333,13 +350,13 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/**
|
||||
* [Node] Does this node have children?
|
||||
*
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param bool $subnodes Include subnodes?
|
||||
* @param mixed $_where Additional WHERE clause
|
||||
* @param string|null $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param Member|null $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param bool $subnodes Include subnodes?
|
||||
* @param mixed $_where Additional WHERE clause
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChildren( $permissionCheck='view', $member=NULL, $subnodes=TRUE, $_where=array() )
|
||||
public function hasChildren( ?string $permissionCheck='view', Member $member=NULL, bool $subnodes=TRUE, mixed $_where=array() ): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -347,14 +364,14 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/**
|
||||
* [Node] Fetch Child Nodes
|
||||
*
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULL to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param bool $subnodes Include subnodes?
|
||||
* @param array|NULL $skip Children IDs to skip
|
||||
* @param mixed $_where Additional WHERE clause
|
||||
* @param string|null $permissionCheck The permission key to check for or NULL to not check permissions
|
||||
* @param Member|null $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param bool|null $subnodes Include subnodes?
|
||||
* @param array|null $skip Children IDs to skip
|
||||
* @param mixed $_where Additional WHERE clause
|
||||
* @return array
|
||||
*/
|
||||
public function children( $permissionCheck='view', $member=NULL, $subnodes=TRUE, $skip=null, $_where=array() )
|
||||
public function children( ?string $permissionCheck='view', Member $member=NULL, bool|null $subnodes=TRUE, array $skip=null, mixed $_where=array() ): array
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@@ -362,22 +379,19 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form ){}
|
||||
public function form( Form &$form ) : void {}
|
||||
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @param bool $skipMember Skip clearing member cache clearing
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function save( $skipMember=FALSE )
|
||||
public function save(): void
|
||||
{
|
||||
$new = $this->_new;
|
||||
|
||||
$this->_skipClearingMenuCache = $skipMember;
|
||||
|
||||
parent::save();
|
||||
|
||||
@@ -387,7 +401,7 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
/* There is a unique constraint against app + perm_type + perm_type_id, so we use replace() instead of insert()
|
||||
in case there is already a row in the database for this constraint */
|
||||
\IPS\Db::i()->replace( 'core_permission_index', array(
|
||||
Db::i()->replace( 'core_permission_index', array(
|
||||
'app' => 'core',
|
||||
'perm_type' => 'module',
|
||||
'perm_type_id' => $this->id,
|
||||
@@ -400,26 +414,5 @@ class _Module extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'modules' );
|
||||
|
||||
/**
|
||||
* @brief Skip clearing create menu cache
|
||||
*/
|
||||
protected $_skipClearingMenuCache = FALSE;
|
||||
|
||||
/**
|
||||
* Clear any defined caches
|
||||
*
|
||||
* @param bool $removeMultiton Should the multiton record also be removed?
|
||||
* @return void
|
||||
*/
|
||||
public function clearCaches( $removeMultiton=FALSE )
|
||||
{
|
||||
parent::clearCaches( $removeMultiton );
|
||||
|
||||
if( $this->_skipClearingMenuCache === FALSE )
|
||||
{
|
||||
\IPS\Member::clearCreateMenu();
|
||||
}
|
||||
}
|
||||
protected array $caches = array( 'modules' );
|
||||
}
|
||||
Reference in new issue
Block a user