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,41 +12,54 @@
|
||||
namespace IPS\core;
|
||||
|
||||
/* 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\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Editor;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Node\Permissions;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored Replies Node
|
||||
*/
|
||||
class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
class StoredReplies extends Model implements Permissions
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_editor_stored_replies';
|
||||
public static ?string $databaseTable = 'core_editor_stored_replies';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'editor_stored_replies';
|
||||
public static string $nodeTitle = 'editor_stored_replies';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databasePrefix = 'reply_';
|
||||
public static string $databasePrefix = 'reply_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -64,7 +77,7 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'core',
|
||||
'module' => 'editor',
|
||||
'all' => 'stored_replies_manage'
|
||||
@@ -73,34 +86,34 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/**
|
||||
* @brief [Node] App for permission index
|
||||
*/
|
||||
public static $permApp = 'core';
|
||||
public static ?string $permApp = 'core';
|
||||
|
||||
/**
|
||||
* @brief [Node] Type for permission index
|
||||
*/
|
||||
public static $permType = 'editorStoredReplies';
|
||||
public static ?string $permType = 'editorStoredReplies';
|
||||
|
||||
/**
|
||||
* @brief The map of permission columns
|
||||
*/
|
||||
public static $permissionMap = array(
|
||||
public static array $permissionMap = array(
|
||||
'view' => 'view'
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] Prefix string that is automatically prepended to permission matrix language strings
|
||||
*/
|
||||
public static $permissionLangPrefix = 'perm_editor_stored_reply_';
|
||||
public static string $permissionLangPrefix = 'perm_editor_stored_reply_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Enabled/Disabled Column
|
||||
*/
|
||||
public static $databaseColumnEnabledDisabled = 'enabled';
|
||||
public static ?string $databaseColumnEnabledDisabled = 'enabled';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'editor_stored_replies_';
|
||||
public static ?string $titleLangPrefix = 'editor_stored_replies_';
|
||||
|
||||
/**
|
||||
* [Node] Get whether or not this node is enabled
|
||||
@@ -108,7 +121,7 @@ class _StoredReplies 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__enabled()
|
||||
protected function get__enabled(): ?bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
@@ -119,7 +132,7 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @param bool|int $enabled Whether to set it enabled or disabled
|
||||
* @return void
|
||||
*/
|
||||
protected function set__enabled( $enabled )
|
||||
protected function set__enabled( bool|int $enabled ) : void
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
@@ -129,7 +142,7 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__title()
|
||||
protected function get__title(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
@@ -137,14 +150,14 @@ class _StoredReplies 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
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'editor_stored_replies_title', $this->id ? $this->title : NULL, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'editor_stored_replies_enabled', $this->id ? $this->enabled : TRUE, FALSE, array( 'togglesOn' => array( 'editor_stored_replies_content' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'editor_stored_replies_content', $this->id ? $this->text : FALSE, FALSE, array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => ( $this->id ? "core-editor-replies-{$this->id}" : "core-editor-replies" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'editor_stored_replies' ) : NULL ), NULL, NULL, NULL, 'editor_stored_replies_content' ) );
|
||||
$form->add( new Text( 'editor_stored_replies_title', $this->id ? $this->title : NULL, TRUE ) );
|
||||
$form->add( new YesNo( 'editor_stored_replies_enabled', $this->id ? $this->enabled : TRUE, FALSE, array( 'togglesOn' => array( 'editor_stored_replies_content' ) ) ) );
|
||||
$form->add( new Editor( 'editor_stored_replies_content', $this->id ? $this->text : FALSE, FALSE, array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => ( $this->id ? "core-editor-replies-{$this->id}" : "core-editor-replies" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'editor_stored_replies' ) : NULL ), NULL, NULL, NULL, 'editor_stored_replies_content' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +166,7 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
foreach( [
|
||||
'editor_stored_replies_title' => 'title',
|
||||
@@ -165,10 +178,7 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
unset( $values[ $input ] );
|
||||
}
|
||||
|
||||
/* Remove any lazy loading stuffs */
|
||||
$values['text'] = \IPS\Text\Parser::removeLazyLoad( $values['text'] );
|
||||
|
||||
$values['added_by'] = \IPS\Member::loggedIn()->loggedIn()->member_id;
|
||||
$values['added_by'] = Member::loggedIn()->loggedIn()->member_id;
|
||||
|
||||
return $values;
|
||||
}
|
||||
@@ -179,20 +189,20 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
public function postSaveForm( array $values ) : void
|
||||
{
|
||||
/* Looks a bit weird, but as this is postSave, $this->id is filled and $this->_new is false, _permissions is always null if it's a new entry */
|
||||
\IPS\File::claimAttachments( ( $this->_permissions === null ) ? "core-editor-replies" : "core-editor-replies-{$this->id}", $this->id, NULL, 'editor_stored_replies' );
|
||||
File::claimAttachments( ( $this->_permissions === null ) ? "core-editor-replies" : "core-editor-replies-{$this->id}", $this->id, NULL, 'editor_stored_replies' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
\IPS\File::unclaimAttachments( 'core_Admin', $this->id, NULL, 'editor_stored_replies' );
|
||||
File::unclaimAttachments( 'core_Admin', $this->id, NULL, 'editor_stored_replies' );
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
@@ -200,21 +210,21 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'editorStoredReplies' );
|
||||
protected array $caches = array( 'editorStoredReplies' );
|
||||
|
||||
/**
|
||||
* Get data store
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStore()
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->editorStoredReplies ) )
|
||||
if ( !isset( Store::i()->editorStoredReplies ) )
|
||||
{
|
||||
/* Don't get the reply text as this could make for a large store [but, dear future developer it might be fine to include it if you really have a need I didn't forsee]
|
||||
Oh and we grab permissions here so we don't need to do a full query each time the editor is loaded */
|
||||
\IPS\Data\Store::i()->editorStoredReplies = iterator_to_array(
|
||||
\IPS\Db::i()->select(
|
||||
Store::i()->editorStoredReplies = iterator_to_array(
|
||||
Db::i()->select(
|
||||
'reply_id, reply_title, reply_added_by, reply_enabled, core_permission_index.perm_id, core_permission_index.perm_view',
|
||||
static::$databaseTable
|
||||
)->join(
|
||||
@@ -224,7 +234,7 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
);
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->editorStoredReplies;
|
||||
return Store::i()->editorStoredReplies;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,11 +243,29 @@ class _StoredReplies extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @param array $insert Permission data to insert
|
||||
* @return void
|
||||
*/
|
||||
public function setPermissions( $insert )
|
||||
public function setPermissions( array $insert ) : void
|
||||
{
|
||||
parent::setPermissions( $insert );
|
||||
|
||||
/* Clear cache */
|
||||
unset( \IPS\Data\Store::i()->editorStoredReplies );
|
||||
unset( Store::i()->editorStoredReplies );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether any replies exist that are enabled (for the logged in member)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function enabledRepliesExist() : bool
|
||||
{
|
||||
foreach ( static::roots() as $root )
|
||||
{
|
||||
if ( $root->_enabled )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user