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
+176
-72
@@ -11,88 +11,111 @@
|
||||
namespace IPS\Content;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Platform\Bridge;
|
||||
use IPS\core\CustomBadge;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Helpers\Form\Upload;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Settings;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function get_called_class;
|
||||
use function intval;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reaction Model
|
||||
*/
|
||||
class _Reaction extends \IPS\Node\Model
|
||||
class Reaction extends Model
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_reactions';
|
||||
public static ?string $databaseTable = 'core_reactions';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'reaction_';
|
||||
public static string $databasePrefix = 'reaction_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'reactions';
|
||||
public static string $nodeTitle = 'reactions';
|
||||
|
||||
/**
|
||||
* @brief [Node] Sortable
|
||||
*/
|
||||
public static $nodeSortable = TRUE;
|
||||
public static bool $nodeSortable = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Positon Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Modal Forms because Charles loves them so
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
public static bool $modalForms = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'reaction_title_';
|
||||
public static ?string $titleLangPrefix = 'reaction_title_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Enabled/Disabled Column
|
||||
*/
|
||||
public static $databaseColumnEnabledDisabled = 'enabled';
|
||||
public static ?string $databaseColumnEnabledDisabled = 'enabled';
|
||||
|
||||
/**
|
||||
* @brief Icon Cache
|
||||
*/
|
||||
public static $icons = array();
|
||||
public static array $icons = array();
|
||||
|
||||
/**
|
||||
* 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\Translatable( 'reaction_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'reaction_title_' . $this->id : NULL ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'reaction_value', $this->id ? $this->value : 1, TRUE, array( 'options' => array( 1 => 'positive', 0 => 'neutral', -1 => 'negative' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'reaction_icon', $this->id ? \IPS\File::get( 'core_Reaction', $this->icon ) : NULL, TRUE, array( 'image' => TRUE, 'storageExtension' => 'core_Reaction', 'storageContainer' => 'reactions', 'obscure' => FALSE ) ) );
|
||||
$form->add( new Translatable( 'reaction_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'reaction_title_' . $this->id : NULL ) ) ) );
|
||||
$form->add( new Radio( 'reaction_value', $this->id ? $this->value : 1, TRUE, array( 'options' => array( 1 => 'positive', 0 => 'neutral', -1 => 'negative' ) ) ) );
|
||||
CustomBadge::getRecordBadge( $this )
|
||||
->addBadgeFieldsToForm( $form, (bool) $this->use_custom, ['reaction_icon'], includeNumberOverlay: false );
|
||||
$form->add( new Upload( 'reaction_icon', $this->id ? File::get( 'core_Reaction', (string) $this->icon ) : NULL, false, array( 'image' => TRUE, 'storageExtension' => 'core_Reaction', 'storageContainer' => 'reactions', 'obscure' => FALSE ), null, null, null, 'reaction_icon' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,14 +124,21 @@ class _Reaction extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if ( !$this->id )
|
||||
{
|
||||
$this->save();
|
||||
}
|
||||
|
||||
if ( array_key_exists( 'badge_use_custom', $values ) )
|
||||
{
|
||||
$values['use_custom'] = $values['badge_use_custom'];
|
||||
}
|
||||
|
||||
CustomBadge::saveRecordBadge( $this, CustomBadge::generateBadgeFromFormValues( $values ) );
|
||||
|
||||
\IPS\Lang::saveCustom( 'core', 'reaction_title_' . $this->id, $values['reaction_title'] );
|
||||
Lang::saveCustom( 'core', 'reaction_title_' . $this->id, $values['reaction_title'] );
|
||||
unset( $values['reaction_title'] );
|
||||
|
||||
return parent::formatFormValues( $values );
|
||||
@@ -117,28 +147,102 @@ class _Reaction extends \IPS\Node\Model
|
||||
/**
|
||||
* [Node] Does the currently logged in user have permission to delete this node?
|
||||
*
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
public function canDelete()
|
||||
public function canDelete(): bool
|
||||
{
|
||||
if ( $this->id === 1 )
|
||||
if ( $this->id === 1 OR Bridge::i()->liveTopicsUnconverted() )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return bool
|
||||
*/
|
||||
public static function canAddRoot() : bool
|
||||
{
|
||||
/* When live topics are in session, prevent users from modifying the content */
|
||||
if ( Bridge::i()->liveTopicsUnconverted() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return parent::canAddRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function canAdd() : bool
|
||||
{
|
||||
if ( Bridge::i()->liveTopicsUnconverted() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return parent::canAdd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function canEdit() : bool
|
||||
{
|
||||
if ( Bridge::i()->liveTopicsUnconverted() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return parent::canEdit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function canManagePermissions() : bool
|
||||
{
|
||||
if ( Bridge::i()->liveTopicsUnconverted() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return parent::canManagePermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function canMassManageContent() : bool
|
||||
{
|
||||
if ( Bridge::i()->liveTopicsUnconverted() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return parent::canMassManageContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function canCopy() : bool
|
||||
{
|
||||
if ( Bridge::i()->liveTopicsUnconverted() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return parent::canCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Icon
|
||||
*
|
||||
* @return \IPS\File
|
||||
* @return mixed
|
||||
*/
|
||||
public function get__icon()
|
||||
public function get__icon(): mixed
|
||||
{
|
||||
if ( !isset( static::$icons[ $this->id ] ) )
|
||||
{
|
||||
static::$icons[ $this->id ] = \IPS\File::get( 'core_Reaction', $this->_data['icon'] );
|
||||
static::$icons[ $this->id ] = $this->use_custom ? CustomBadge::getRecordBadge( $this )->url() : File::get( 'core_Reaction', $this->_data['icon'] );
|
||||
}
|
||||
|
||||
return static::$icons[ $this->id ];
|
||||
@@ -147,21 +251,21 @@ class _Reaction extends \IPS\Node\Model
|
||||
/**
|
||||
* Get Description
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function get__description()
|
||||
public function get__description(): ?string
|
||||
{
|
||||
if ( $this->value == 1 )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('positive');
|
||||
return Member::loggedIn()->language()->addToStack('positive');
|
||||
}
|
||||
elseif ( $this->value == -1 )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('negative');
|
||||
return Member::loggedIn()->language()->addToStack('negative');
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('neutral');
|
||||
return Member::loggedIn()->language()->addToStack('neutral');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,16 +273,16 @@ class _Reaction extends \IPS\Node\Model
|
||||
* Fetch All Root 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 Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @param array|NULL $limit Limit/offset to use, or NULL for no limit (default)
|
||||
* @return array
|
||||
* @return (static|Model)[]|static[]
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $limit=NULL )
|
||||
public static function roots( ?string $permissionCheck='view', Member|null $member=NULL, mixed $where=array(), array $limit=NULL ): array
|
||||
{
|
||||
if ( !\count( $where ) )
|
||||
if ( !count( $where ) )
|
||||
{
|
||||
$cacheKey = md5( \get_called_class() . $permissionCheck );
|
||||
$cacheKey = md5( get_called_class() . $permissionCheck );
|
||||
|
||||
if( isset( static::$rootsResult[ $cacheKey ] ) )
|
||||
{
|
||||
@@ -205,7 +309,7 @@ class _Reaction extends \IPS\Node\Model
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__enabled()
|
||||
protected function get__enabled(): ?bool
|
||||
{
|
||||
if ( $this->id == 1 )
|
||||
{
|
||||
@@ -220,14 +324,14 @@ class _Reaction extends \IPS\Node\Model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStore()
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->reactions ) )
|
||||
if ( !isset( Store::i()->reactions ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->reactions = iterator_to_array( \IPS\Db::i()->select( '*', 'core_reactions', NULL, "reaction_position ASC" )->setKeyField( 'reaction_id' ) );
|
||||
Store::i()->reactions = iterator_to_array( Db::i()->select( '*', 'core_reactions', NULL, "reaction_position ASC" )->setKeyField( 'reaction_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->reactions;
|
||||
return Store::i()->reactions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,22 +339,22 @@ class _Reaction extends \IPS\Node\Model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isLikeMode()
|
||||
public static function isLikeMode(): bool
|
||||
{
|
||||
return (bool) \IPS\Settings::i()->reaction_is_likemode;
|
||||
return (bool) Settings::i()->reaction_is_likemode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Attempt to load from cache
|
||||
* @note If this is set to TRUE you MUST define a getStore() method to return the objects from cache
|
||||
*/
|
||||
protected static $loadFromCache = TRUE;
|
||||
protected static bool $loadFromCache = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'reactions' );
|
||||
protected array $caches = array( 'reactions' );
|
||||
|
||||
/**
|
||||
* Clear any defined caches
|
||||
@@ -258,7 +362,7 @@ class _Reaction extends \IPS\Node\Model
|
||||
* @param bool $removeMultiton Should the multiton record also be removed?
|
||||
* @return void
|
||||
*/
|
||||
public function clearCaches( $removeMultiton=FALSE )
|
||||
public function clearCaches( bool $removeMultiton=FALSE ): void
|
||||
{
|
||||
parent::clearCaches( $removeMultiton );
|
||||
|
||||
@@ -270,21 +374,21 @@ class _Reaction extends \IPS\Node\Model
|
||||
* Example code explains return value
|
||||
*
|
||||
* @code
|
||||
array(
|
||||
array(
|
||||
'icon' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
'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' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
* '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 = parent::getButtons( $url, $subnode );
|
||||
|
||||
@@ -294,7 +398,7 @@ class _Reaction extends \IPS\Node\Model
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'delete',
|
||||
'link' => $url->setQueryString( array( 'do' => 'delete', 'id' => $this->_id ) ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('delete') ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('delete') ),
|
||||
'hotkey'=> 'd'
|
||||
);
|
||||
}
|
||||
@@ -306,9 +410,9 @@ class _Reaction extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function updateLikeModeSetting()
|
||||
public static function updateLikeModeSetting(): void
|
||||
{
|
||||
\IPS\Settings::i()->changeValues( array( 'reaction_is_likemode' => \intval( \count( static::enabledReactions() ) == 1 ) ) );
|
||||
Settings::i()->changeValues( array( 'reaction_is_likemode' => intval( count( static::enabledReactions() ) == 1 ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +420,7 @@ class _Reaction extends \IPS\Node\Model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function enabledReactions()
|
||||
public static function enabledReactions(): array
|
||||
{
|
||||
return array_filter(
|
||||
static::roots(),
|
||||
@@ -331,7 +435,7 @@ class _Reaction extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
public function __clone(): void
|
||||
{
|
||||
if ( $this->skipCloneDuplication === TRUE )
|
||||
{
|
||||
@@ -344,12 +448,12 @@ class _Reaction extends \IPS\Node\Model
|
||||
|
||||
try
|
||||
{
|
||||
$icon = \IPS\File::get( 'core_Reaction', $oldIcon );
|
||||
$newIcon = \IPS\File::create( 'core_Reaction', $icon->originalFilename, $icon->contents() );
|
||||
$icon = File::get( 'core_Reaction', $oldIcon );
|
||||
$newIcon = File::create( 'core_Reaction', $icon->originalFilename, $icon->contents() );
|
||||
$this->icon = (string) $newIcon;
|
||||
}
|
||||
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
$this->icon = NULL;
|
||||
}
|
||||
@@ -360,15 +464,15 @@ class _Reaction extends \IPS\Node\Model
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'core_Reaction', $this->icon )->delete();
|
||||
File::get( 'core_Reaction', $this->icon )->delete();
|
||||
}
|
||||
catch( \Exception $ex ) { }
|
||||
catch( Exception $ex ) { }
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user