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

+56 -38
View File
@@ -11,21 +11,33 @@
namespace IPS\core\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Api\Exception;
use IPS\Api\PaginatedResponse;
use IPS\Api\Response;
use IPS\core\Warnings\Reason;
use IPS\Lang;
use IPS\Node\Api\NodeController;
use IPS\Node\Model;
use IPS\Request;
use OutOfRangeException;
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 Warn Reasons API
*/
class _warnreasons extends \IPS\Node\Api\NodeController
class warnreasons extends NodeController
{
/**
* Class
*/
protected $class = 'IPS\core\Warnings\Reason';
protected string $class = 'IPS\core\Warnings\Reason';
/**
* GET /core/warnreasons
@@ -33,15 +45,16 @@ class _warnreasons extends \IPS\Node\Api\NodeController
*
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @return \IPS\Api\PaginatedResponse<IPS\core\Warnings\Reason>
* @apireturn PaginatedResponse<IPS\core\Warnings\Reason>
* @throws 1C292/S NO_PERMISSION The current authorized user does not have permission to issue warnings and as such cannot view the list of warn reasons
* @return PaginatedResponse<Reason>
*/
public function GETindex()
public function GETindex() : PaginatedResponse
{
/* Check permissions */
if( $this->member AND ( !$this->member->modPermission('mod_can_warn') OR !$this->member->modPermission('mod_see_warn') ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '1C292/S', 403 );
throw new Exception( 'NO_PERMISSION', '1C292/S', 403 );
}
/* Return */
@@ -55,17 +68,18 @@ class _warnreasons extends \IPS\Node\Api\NodeController
* @apiclientonly
* @param int $id ID Number
* @throws 1C385/1 INVALID_ID The warn reason does not exist
* @return \IPS\core\Warnings\Reason
* @apireturn \IPS\core\Warnings\Reason
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ) : Response
{
try
{
return $this->_view( $id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C385/1', 404 );
throw new Exception( 'INVALID_ID', '1C385/1', 404 );
}
}
@@ -81,23 +95,24 @@ class _warnreasons extends \IPS\Node\Api\NodeController
* @apiparam bool pointsAutoRemove Whether or not to automatically remove points (defaults to false). If true, you must supply removePoints.
* @apiparam string|null removePoints Timeframe to remove points after as a date interval (e.g. P2D for 2 days or PT6H for 6 hours)
* @apiparam bool removeOverride Whether or not moderators can override the default points removal configuration
* @return \IPS\core\Warnings\Reason
* @apireturn \IPS\core\Warnings\Reason
* @throws 1C385/2 INVALID_POINTS_EXPIRATION Points were specified as automatically removing but the removal time period was not supplied or is invalid
* @throws 1C385/4 NO_NAME A name for the warn reason must be supplied
* @return Response
*/
public function POSTindex()
public function POSTindex() : Response
{
if( !\IPS\Request::i()->name )
if( !Request::i()->name )
{
throw new \IPS\Api\Exception( 'NO_NAME', '1C385/4', 400 );
throw new Exception( 'NO_NAME', '1C385/4', 400 );
}
if( isset( \IPS\Request::i()->pointsAutoRemove ) AND \IPS\Request::i()->pointsAutoRemove AND ( !isset( \IPS\Request::i()->removePoints ) OR !\IPS\Request::i()->removePoints ) )
if( isset( Request::i()->pointsAutoRemove ) AND Request::i()->pointsAutoRemove AND ( !isset( Request::i()->removePoints ) OR !Request::i()->removePoints ) )
{
throw new \IPS\Api\Exception( 'INVALID_POINTS_EXPIRATION', '1C385/2', 400 );
throw new Exception( 'INVALID_POINTS_EXPIRATION', '1C385/2', 400 );
}
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
return new Response( 201, $this->_create()->apiOutput( $this->member ) );
}
/**
@@ -113,20 +128,22 @@ class _warnreasons extends \IPS\Node\Api\NodeController
* @apiparam string|null removePoints Timeframe to remove points after as a date interval (e.g. P2D for 2 days or PT6H for 6 hours)
* @apiparam bool removeOverride Whether or not moderators can override the default points removal configuration
* @param int $id ID Number
* @return \IPS\core\Warnings\Reason
* @apireturn \IPS\core\Warnings\Reason
* @throws 1C385/3 INVALID_POINTS_EXPIRATION Points were specified as automatically removing but the removal time period was not supplied or is invalid
* @return Response
*/
public function POSTitem( $id )
public function POSTitem( int $id ) : Response
{
if( isset( \IPS\Request::i()->pointsAutoRemove ) AND \IPS\Request::i()->pointsAutoRemove AND ( !isset( \IPS\Request::i()->removePoints ) OR !\IPS\Request::i()->removePoints ) )
if( isset( Request::i()->pointsAutoRemove ) AND Request::i()->pointsAutoRemove AND ( !isset( Request::i()->removePoints ) OR !Request::i()->removePoints ) )
{
throw new \IPS\Api\Exception( 'INVALID_POINTS_EXPIRATION', '1C385/3', 400 );
throw new Exception( 'INVALID_POINTS_EXPIRATION', '1C385/3', 400 );
}
/* @var Reason $class */
$class = $this->class;
$reason = $class::load( $id );
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $reason )->apiOutput( $this->member ) );
return new Response( 200, $this->_createOrUpdate( $reason )->apiOutput( $this->member ) );
}
/**
@@ -135,9 +152,10 @@ class _warnreasons extends \IPS\Node\Api\NodeController
*
* @apiclientonly
* @param int $id ID Number
* @return void
* @apireturn void
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ) : Response
{
return $this->_delete( $id );
}
@@ -145,33 +163,33 @@ class _warnreasons extends \IPS\Node\Api\NodeController
/**
* Create or update node
*
* @param \IPS\node\Model $reason The node
* @return \IPS\node\Model
* @param Model $reason The node
* @return Model
*/
protected function _createOrUpdate( \IPS\Node\Model $reason )
protected function _createOrUpdate( Model $reason ): Model
{
if( \IPS\Request::i()->name )
if( Request::i()->name )
{
\IPS\Lang::saveCustom( 'core', 'core_warn_reason_' . $reason->id, \IPS\Request::i()->name );
Lang::saveCustom( 'core', 'core_warn_reason_' . $reason->id, Request::i()->name );
}
$reason->points = (int) \IPS\Request::i()->points;
$reason->points_override = (bool) \IPS\Request::i()->pointsOverride;
$reason->remove_override = (bool) \IPS\Request::i()->removeOverride;
$reason->notes = \IPS\Request::i()->notes;
$reason->points = (int) Request::i()->points;
$reason->points_override = (bool) Request::i()->pointsOverride;
$reason->remove_override = (bool) Request::i()->removeOverride;
$reason->notes = Request::i()->notes;
if( isset( \IPS\Request::i()->pointsAutoRemove ) OR isset( \IPS\Request::i()->removePoints ) )
if( isset( Request::i()->pointsAutoRemove ) OR isset( Request::i()->removePoints ) )
{
if( !\IPS\Request::i()->pointsAutoRemove )
if( !Request::i()->pointsAutoRemove )
{
$reason->remove = -1;
$reason->remove_unit = NULL;
}
else
{
$reason->remove = (int) str_ireplace( array( 'P', 'T', 'H' ), '', \IPS\Request::i()->removePoints );
$reason->remove = (int) str_ireplace( array( 'P', 'T', 'H' ), '', Request::i()->removePoints );
if( mb_strpos( \IPS\Request::i()->removePoints, 'PT' ) === 0 )
if( mb_strpos( Request::i()->removePoints, 'PT' ) === 0 )
{
$reason->remove_unit = 'h';
}