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,14 +12,29 @@
|
||||
namespace IPS\convert\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Content\Reaction;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
class _Reactionmapper extends \IPS\Helpers\Form\FormAbstract
|
||||
class Reactionmapper extends FormAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -30,27 +45,27 @@ class _Reactionmapper extends \IPS\Helpers\Form\FormAbstract
|
||||
public function html() : string
|
||||
{
|
||||
/* Setup our local reaction descriptions and options */
|
||||
foreach( \IPS\Content\Reaction::getStore() as $ipsReaction )
|
||||
foreach( Content\Reaction::getStore() as $ipsReaction )
|
||||
{
|
||||
$this->options['options'][ $ipsReaction['reaction_id'] ] = (string) \IPS\File::get( 'core_Reaction', $ipsReaction['reaction_icon'] )->url;
|
||||
$this->options['descriptions'][ $ipsReaction['reaction_id'] ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $ipsReaction['reaction_id'] );
|
||||
$this->options['options'][ $ipsReaction['reaction_id'] ] = (string) File::get( 'core_Reaction', $ipsReaction['reaction_icon'] )->url;
|
||||
$this->options['descriptions'][ $ipsReaction['reaction_id'] ] = Member::loggedIn()->language()->addToStack('reaction_title_' . $ipsReaction['reaction_id'] );
|
||||
}
|
||||
|
||||
/* Specific options for creating a new reaction */
|
||||
$this->options['options'][ 'none' ] = FALSE;
|
||||
$this->options['descriptions']['none'] = \IPS\Member::loggedIn()->language()->addToStack('convert_create_reaction' );
|
||||
$this->options['descriptions']['none'] = Member::loggedIn()->language()->addToStack('convert_create_reaction' );
|
||||
|
||||
/* Get our controller */
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_forms.js', 'convert' ) );
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_forms.js', 'convert' ) );
|
||||
|
||||
/* Sort out the pre-selected value */
|
||||
$value = $this->value;
|
||||
if ( !\is_array( $this->value ) AND $this->value !== NULL AND $this->value !== '' )
|
||||
if ( !is_array( $this->value ) AND $this->value !== NULL AND $this->value !== '' )
|
||||
{
|
||||
$value = array( $this->value );
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'forms' )->reactionmapper( $this->name, $value, $this->options['reactions'], $this->options['options'], $this->options['descriptions'] );
|
||||
return Theme::i()->getTemplate( 'forms' )->reactionmapper( $this->name, $value, $this->options['reactions'], $this->options['options'], $this->options['descriptions'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,10 +73,10 @@ class _Reactionmapper extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): mixed
|
||||
{
|
||||
$name = $this->name;
|
||||
$value = \IPS\Request::i()->$name;
|
||||
$value = Request::i()->$name;
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -69,18 +84,18 @@ class _Reactionmapper extends \IPS\Helpers\Form\FormAbstract
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \DomainException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws DomainException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
public function validate(): bool
|
||||
{
|
||||
parent::validate();
|
||||
|
||||
/* Check all of the values are present */
|
||||
if( \count( $this->value ) !== \count( $this->options['reactions'] ) )
|
||||
if( count( $this->value ) !== count( $this->options['reactions'] ) )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'err_convert_reaction' );
|
||||
throw new InvalidArgumentException( 'err_convert_reaction' );
|
||||
}
|
||||
|
||||
/* Check that the values are valid reactions, or 'none' */
|
||||
@@ -95,7 +110,7 @@ class _Reactionmapper extends \IPS\Helpers\Form\FormAbstract
|
||||
/* Zero is an unselected reaction */
|
||||
if( (int) $value === 0 )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'err_convert_reaction_not_selected' );
|
||||
throw new InvalidArgumentException( 'err_convert_reaction_not_selected' );
|
||||
}
|
||||
|
||||
/* Any value greater than zero is an IPS reaction ID */
|
||||
@@ -103,11 +118,11 @@ class _Reactionmapper extends \IPS\Helpers\Form\FormAbstract
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Content\Reaction::load( $value );
|
||||
Reaction::load( $value );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'err_convert_reaction_not_exist' );
|
||||
throw new InvalidArgumentException( 'err_convert_reaction_not_exist' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user