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,21 +12,33 @@
|
||||
namespace IPS\downloads\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\downloads\Category;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Lang;
|
||||
use IPS\Node\Api\NodeController;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
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 Downloads Category API
|
||||
*/
|
||||
class _categories extends \IPS\Node\Api\NodeController
|
||||
class categories extends NodeController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\downloads\Category';
|
||||
protected string $class = 'IPS\downloads\Category';
|
||||
|
||||
/**
|
||||
* GET /downloads/categories
|
||||
@@ -36,9 +48,10 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @note For requests using an OAuth Access Token for a particular member, only categories the authorized user can view will be included
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\downloads\Category>
|
||||
* @apireturn PaginatedResponse<IPS\downloads\Category>
|
||||
* @return PaginatedResponse<Category>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Return */
|
||||
return $this->_list();
|
||||
@@ -49,9 +62,10 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* Get specific category
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\downloads\Category>
|
||||
* @apireturn IPS\downloads\Category
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
/* Return */
|
||||
return $this->_view( $id );
|
||||
@@ -72,17 +86,18 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int reviews_mod Reviews must be approved?
|
||||
* @apiparam int reviews_download Files must be downloaded before a review can be left?
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, download, reply, review) and values as permissions to use (which may be * to grant access to all groups, or an array of group IDs to permit access to)
|
||||
* @return \IPS\downloads\Category
|
||||
* @apireturn \IPS\downloads\Category
|
||||
* @throws 1D365/2 NO_TITLE A title for the category must be supplied
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTindex()
|
||||
public function POSTindex(): Response
|
||||
{
|
||||
if ( !\IPS\Request::i()->title )
|
||||
if ( !Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '1D365/2', 400 );
|
||||
throw new Exception( 'NO_TITLE', '1D365/2', 400 );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
return new Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,14 +116,16 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int reviews_download Files must be downloaded before a review can be left?
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, download, reply, review) and values as permissions to use (which may be * to grant access to all groups, or an array of group IDs to permit access to)
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\downloads\Category
|
||||
* @apireturn \IPS\downloads\Category
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
/* @var Category $class */
|
||||
$class = $this->class;
|
||||
$category = $class::load( $id );
|
||||
|
||||
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $category )->apiOutput( $this->member ) );
|
||||
return new Response( 200, $this->_createOrUpdate( $category )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,44 +134,45 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int deleteChildrenOrMove The ID number of the new parent or -1 to delete all child nodes.
|
||||
* @return void
|
||||
* @apireturn void
|
||||
* @throws 1S359/1 INVALID_ID The node ID does not exist
|
||||
* @throws 1S359/2 INVALID_TARGET The target node cannot be deleted because the new parent node does not exist
|
||||
* @throws 1S359/3 HAS_CHILDREN The target node cannot be deleted because it has children (pass deleteChildrenOrMove in the request to specify how to handle the children)
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
public function DELETEitem( int $id ): Response
|
||||
{
|
||||
return $this->_delete( $id, \IPS\Request::i()->deleteChildrenOrMove ?? NULL );
|
||||
return $this->_delete( $id, Request::i()->deleteChildrenOrMove ?? NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update node
|
||||
*
|
||||
* @param \IPS\node\Model $category The node
|
||||
* @return \IPS\node\Model
|
||||
* @param Model $category The node
|
||||
* @return Model
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\Node\Model $category )
|
||||
protected function _createOrUpdate( Model $category ): Model
|
||||
{
|
||||
foreach ( array( 'title' => "downloads_category_{$category->id}", 'description' => "downloads_category_{$category->id}_desc" ) as $fieldKey => $langKey )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$fieldKey ) )
|
||||
if ( isset( Request::i()->$fieldKey ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'downloads', $langKey, \IPS\Request::i()->$fieldKey );
|
||||
Lang::saveCustom( 'downloads', $langKey, Request::i()->$fieldKey );
|
||||
|
||||
if ( $fieldKey === 'title' )
|
||||
{
|
||||
$category->name_furl = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->$fieldKey );
|
||||
$category->name_furl = Friendly::seoTitle( Request::i()->$fieldKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$category->parent = (int) \IPS\Request::i()->parent?: 0;
|
||||
$category->parent = (int) Request::i()->parent?: 0;
|
||||
|
||||
foreach ( array( 'moderation', 'moderation_edits', 'allowss', 'reqss', 'comments', 'comment_moderation', 'reviews', 'reviews_mod', 'reviews_download' ) as $k )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$k ) )
|
||||
if ( isset( Request::i()->$k ) )
|
||||
{
|
||||
$category->bitoptions[ $k ] = \IPS\Request::i()->$k;
|
||||
$category->bitoptions[ $k ] = Request::i()->$k;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,21 +12,34 @@
|
||||
namespace IPS\downloads\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Api\Exception;
|
||||
use IPS\Api\PaginatedResponse;
|
||||
use IPS\Api\Response;
|
||||
use IPS\Content\Api\CommentController;
|
||||
use IPS\downloads\File;
|
||||
use IPS\downloads\File\Comment;
|
||||
use IPS\Member;
|
||||
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 Downloads File Comments API
|
||||
*/
|
||||
class _comments extends \IPS\Content\Api\CommentController
|
||||
class comments extends CommentController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\downloads\File\Comment';
|
||||
protected string $class = 'IPS\downloads\File\Comment';
|
||||
|
||||
/**
|
||||
* GET /downloads/comments
|
||||
@@ -42,11 +55,12 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\downloads\File\Comment>
|
||||
* @apireturn PaginatedResponse<IPS\downloads\File\Comment>
|
||||
* @return PaginatedResponse<Comment>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
return $this->_list( array(), 'categories' );
|
||||
return $this->_list();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +69,14 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2D304/1 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\downloads\File\Comment
|
||||
* @apireturn \IPS\downloads\File\Comment
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var Comment $class */
|
||||
$class = $this->class;
|
||||
if ( $this->member )
|
||||
{
|
||||
@@ -71,11 +87,11 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
$object = $class::load( $id );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
return new Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D304/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2D304/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,18 +112,19 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* @throws 1D304/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1D304/4 NO_CONTENT No content was supplied
|
||||
* @throws 2D304/8 NO_PERMISSION The authorized user does not have permission to comment on that file
|
||||
* @return \IPS\downloads\File\Comment
|
||||
* @apireturn \IPS\downloads\File\Comment
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTindex()
|
||||
public function POSTindex(): Response
|
||||
{
|
||||
/* Get file */
|
||||
try
|
||||
{
|
||||
$file = \IPS\downloads\File::load( \IPS\Request::i()->file );
|
||||
$file = File::load( Request::i()->file );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D304/2', 403 );
|
||||
throw new Exception( 'INVALID_ID', '2D304/2', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
@@ -115,38 +132,38 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
if ( !$file->canComment( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2D304/8', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2D304/8', 403 );
|
||||
}
|
||||
$author = $this->member;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Request::i()->author )
|
||||
if ( Request::i()->author )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author );
|
||||
$author = Member::load( Request::i()->author );
|
||||
if ( !$author->member_id )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1D304/3', 404 );
|
||||
throw new Exception( 'NO_AUTHOR', '1D304/3', 404 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Request::i()->author === 0 )
|
||||
if ( Request::i()->author === 0 )
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
$author = new Member;
|
||||
$author->name = Request::i()->author_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1D304/3', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1D304/3', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
if ( !\IPS\Request::i()->content )
|
||||
if ( !Request::i()->content )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_CONTENT', '1D304/4', 403 );
|
||||
throw new Exception( 'NO_CONTENT', '1D304/4', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
@@ -167,21 +184,22 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* @throws 2D304/5 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
|
||||
* @throws 1D304/6 NO_AUTHOR The author ID does not exist
|
||||
* @throws 2D304/9 NO_PERMISSION The authorized user does not have permission to edit the comment
|
||||
* @return \IPS\downloads\File\Comment
|
||||
* @apireturn \IPS\downloads\File\Comment
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Load */
|
||||
$comment = \IPS\downloads\File\Comment::load( $id );
|
||||
$comment = Comment::load( $id );
|
||||
if ( $this->member and !$comment->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
if ( $this->member and !$comment->canEdit( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2D304/9', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2D304/9', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
@@ -189,14 +207,14 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
return $this->_edit( $comment );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
catch ( InvalidArgumentException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1D304/6', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1D304/6', 400 );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D304/5', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2D304/5', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,25 +225,27 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* @param int $id ID Number
|
||||
* @throws 2D304/7 INVALID_ID The comment ID does not exist
|
||||
* @throws 2D304/A NO_PERMISSION The authorized user does not have permission to delete the comment
|
||||
* @return void
|
||||
* @apireturn void
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
public function DELETEitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
/* @var Comment $class */
|
||||
$class = $this->class;
|
||||
$object = $class::load( $id );
|
||||
if ( $this->member and !$object->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2D304/A', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2D304/A', 403 );
|
||||
}
|
||||
$object->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
return new Response( 200, NULL );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D304/7', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2D304/7', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,14 +256,15 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* @param int $id ID Number
|
||||
* @apiparam int id ID of the reaction to add
|
||||
* @apiparam int author ID of the member reacting
|
||||
* @return \IPS\downloads\File\Comment
|
||||
* @apireturn \IPS\downloads\File\Comment
|
||||
* @throws 1S425/2 NO_REACTION The reaction ID does not exist
|
||||
* @throws 1S425/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/4 REACT_ERROR Error adding the reaction
|
||||
* @throws 1S425/5 INVALID_ID Object ID does not exist
|
||||
* @note If the author has already reacted to this content, any existing reaction will be removed first
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem_react( $id )
|
||||
public function POSTitem_react( int $id ): Response
|
||||
{
|
||||
return $this->_reactAdd( $id );
|
||||
}
|
||||
@@ -254,13 +275,14 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author ID of the member who reacted
|
||||
* @return \IPS\downloads\File\Comment
|
||||
* @apireturn \IPS\downloads\File\Comment
|
||||
* @throws 1S425/6 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/7 REACT_ERROR Error adding the reaction
|
||||
* @throws 1S425/8 INVALID_ID Object ID does not exist
|
||||
* @note If the author has already reacted to this content, any existing reaction will be removed first
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem_react( $id )
|
||||
public function DELETEitem_react( int $id ): Response
|
||||
{
|
||||
return $this->_reactRemove( $id );
|
||||
}
|
||||
@@ -275,9 +297,10 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* @apiparam string message Optional message
|
||||
* @throws 1S425/B NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/C REPORTED_ALREADY The member has reported this item in the past 24 hours
|
||||
* @return \IPS\downloads\File\Comment
|
||||
* @apireturn \IPS\downloads\File\Comment
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem_report( $id )
|
||||
public function POSTitem_report( int $id ): Response
|
||||
{
|
||||
return $this->_report( $id );
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,21 +12,36 @@
|
||||
namespace IPS\downloads\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Api\Exception;
|
||||
use IPS\Api\PaginatedResponse;
|
||||
use IPS\Api\Response;
|
||||
use IPS\Content\Api\CommentController;
|
||||
use IPS\downloads\File;
|
||||
use IPS\downloads\File\Review;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Downloads File Reviews API
|
||||
*/
|
||||
class _reviews extends \IPS\Content\Api\CommentController
|
||||
class reviews extends CommentController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\downloads\File\Review';
|
||||
protected string $class = 'IPS\downloads\File\Review';
|
||||
|
||||
/**
|
||||
* GET /downloads/reviews
|
||||
@@ -42,11 +57,12 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\downloads\File\Review>
|
||||
* @apireturn PaginatedResponse<IPS\downloads\File\Review>
|
||||
* @return PaginatedResponse<Review>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
return $this->_list( array(), 'categories' );
|
||||
return $this->_list();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +71,14 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2D305/1 INVALID_ID The review ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\downloads\File\Review
|
||||
* @apireturn \IPS\downloads\File\Review
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var Review $class */
|
||||
$class = $this->class;
|
||||
if ( $this->member )
|
||||
{
|
||||
@@ -71,11 +89,11 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
$object = $class::load( $id );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
return new Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D305/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2D305/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,18 +116,19 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* @throws 1D305/4 NO_CONTENT No content was supplied
|
||||
* @throws 1D305/5 INVALID_RATING The rating is not a valid number up to the maximum rating
|
||||
* @throws 2D305/A NO_PERMISSION The authorized user does not have permission to review that file
|
||||
* @return \IPS\downloads\File\Review
|
||||
* @apireturn \IPS\downloads\File\Review
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTindex()
|
||||
public function POSTindex(): Response
|
||||
{
|
||||
/* Get file */
|
||||
try
|
||||
{
|
||||
$file = \IPS\downloads\File::load( \IPS\Request::i()->file );
|
||||
$file = File::load( Request::i()->file );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D305/2', 403 );
|
||||
throw new Exception( 'INVALID_ID', '2D305/2', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
@@ -117,44 +136,44 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
if ( !$file->canReview( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2D305/A', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2D305/A', 403 );
|
||||
}
|
||||
$author = $this->member;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Request::i()->author )
|
||||
if ( Request::i()->author )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author );
|
||||
$author = Member::load( Request::i()->author );
|
||||
if ( !$author->member_id )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1D305/3', 404 );
|
||||
throw new Exception( 'NO_AUTHOR', '1D305/3', 404 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Request::i()->author === 0 )
|
||||
if ( Request::i()->author === 0 )
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
$author = new Member;
|
||||
$author->name = Request::i()->author_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1D305/3', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1D305/3', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
if ( !\IPS\Request::i()->content )
|
||||
if ( !Request::i()->content )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_CONTENT', '1D305/4', 403 );
|
||||
throw new Exception( 'NO_CONTENT', '1D305/4', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a rating */
|
||||
if ( !\IPS\Request::i()->rating or !\in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
|
||||
if ( !Request::i()->rating or !in_array( (int) Request::i()->rating, range( 1, Settings::i()->reviews_rating_out_of ) ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_RATING', '1D305/5', 403 );
|
||||
throw new Exception( 'INVALID_RATING', '1D305/5', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
@@ -177,41 +196,42 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* @throws 1D305/7 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1D305/8 INVALID_RATING The rating is not a valid number up to the maximum rating
|
||||
* @throws 2D305/B NO_PERMISSION The authorized user does not have permission to edit the review
|
||||
* @return \IPS\downloads\File\Review
|
||||
* @apireturn \IPS\downloads\File\Review
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Load */
|
||||
$comment = \IPS\downloads\File\Review::load( $id );
|
||||
$comment = Review::load( $id );
|
||||
if ( $this->member and !$comment->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
if ( $this->member and !$comment->canEdit( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2D305/B', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2D305/B', 403 );
|
||||
}
|
||||
|
||||
/* Check */
|
||||
if ( isset( \IPS\Request::i()->rating ) and !\in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
|
||||
if ( isset( Request::i()->rating ) and !in_array( (int) Request::i()->rating, range( 1, Settings::i()->reviews_rating_out_of ) ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_RATING', '1D305/8', 403 );
|
||||
throw new Exception( 'INVALID_RATING', '1D305/8', 403 );
|
||||
}
|
||||
/* Do it */
|
||||
try
|
||||
{
|
||||
return $this->_edit( $comment );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
catch ( InvalidArgumentException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1D305/7', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1D305/7', 400 );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D305/6', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2D305/6', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,25 +242,27 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* @param int $id ID Number
|
||||
* @throws 2D305/9 INVALID_ID The review ID does not exist
|
||||
* @throws 2D305/C NO_PERMISSION The authorized user does not have permission to delete the comment
|
||||
* @return void
|
||||
* @apireturn void
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
public function DELETEitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
/* @var Review $class */
|
||||
$class = $this->class;
|
||||
$object = $class::load( $id );
|
||||
if ( $this->member and !$object->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2D305/C', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2D305/C', 403 );
|
||||
}
|
||||
$object->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
return new Response( 200, NULL );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2D305/9', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2D305/9', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,14 +273,15 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* @param int $id ID Number
|
||||
* @apiparam int id ID of the reaction to add
|
||||
* @apiparam int author ID of the member reacting
|
||||
* @return \IPS\downloads\File\Reviews
|
||||
* @apireturn \IPS\downloads\File\Review
|
||||
* @throws 1S425/2 NO_REACTION The reaction ID does not exist
|
||||
* @throws 1S425/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/4 REACT_ERROR Error adding the reaction
|
||||
* @throws 1S425/5 INVALID_ID Object ID does not exist
|
||||
* @note If the author has already reacted to this content, any existing reaction will be removed first
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem_react( $id )
|
||||
public function POSTitem_react( int $id ): Response
|
||||
{
|
||||
return $this->_reactAdd( $id );
|
||||
}
|
||||
@@ -269,13 +292,14 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author ID of the member who reacted
|
||||
* @return \IPS\downloads\File\Reviews
|
||||
* @apireturn \IPS\downloads\File\Review
|
||||
* @throws 1S425/6 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/7 REACT_ERROR Error adding the reaction
|
||||
* @throws 1S425/8 INVALID_ID Object ID does not exist
|
||||
* @note If the author has already reacted to this content, any existing reaction will be removed first
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem_react( $id )
|
||||
public function DELETEitem_react( int $id ): Response
|
||||
{
|
||||
return $this->_reactRemove( $id );
|
||||
}
|
||||
@@ -290,9 +314,10 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* @apiparam string message Optional message
|
||||
* @throws 1S425/B NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/C REPORTED_ALREADY The member has reported this item in the past 24 hours
|
||||
* @return \IPS\downloads\File\Reviews
|
||||
* @apireturn \IPS\downloads\File\Review
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem_report( $id )
|
||||
public function POSTitem_report( int $id ): Response
|
||||
{
|
||||
return $this->_report( $id );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user