Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -32,6 +32,7 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* GET /gallery/reviews
|
||||
* Get list of reviews
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only reviews the authorized user can view will be included
|
||||
* @apiparam string categories Comma-delimited list of category IDs (will also include images in albums in those categories)
|
||||
* @apiparam string albums Comma-delimited list of album IDs
|
||||
* @apiparam string authors Comma-delimited list of member IDs - if provided, only topics started by those members are returned
|
||||
@@ -41,6 +42,7 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'title' or leave unspecified for ID
|
||||
* @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\gallery\Image\Review>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -62,14 +64,24 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* View information about a specific review
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2G318/1 INVALID_ID The review ID does not exist
|
||||
* @throws 2G318/1 INVALID_ID The review ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\gallery\Image\Review
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\gallery\Image\Review::load( $id )->apiOutput() );
|
||||
$class = $this->class;
|
||||
if ( $this->member )
|
||||
{
|
||||
$object = $class::loadAndCheckPerms( $id, $this->member );
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = $class::load( $id );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -81,23 +93,25 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* POST /gallery/reviews
|
||||
* Create a review
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
|
||||
* @reqapiparam int image The ID number of the image the review is for
|
||||
* @reqapiparam int author The ID number of the member making the review (0 for guest)
|
||||
* @reqapiparam int author The ID number of the member making the review (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author
|
||||
* @apiparam string author_name If author is 0, the guest name that should be used
|
||||
* @reqapiparam string content The review content as HTML (e.g. "<p>This is a review.</p>")
|
||||
* @apiparam datetime date The date/time that should be used for the review date. If not provided, will use the current date/time
|
||||
* @apiparam string ip_address The IP address that should be stored for the review. If not provided, will use the IP address from the API request
|
||||
* @reqapiparam string content The review content as HTML (e.g. "<p>This is a review.</p>"). Will be sanatized for requests using an OAuth Access Token for a particular member; will be saved unaltered for requests made using an API Key or the Client Credentials Grant Type.
|
||||
* @apiparam datetime date The date/time that should be used for the review date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam string ip_address The IP address that should be stored for the review. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
|
||||
* @reqapiparam int rating Star rating
|
||||
* @throws 2G318/8 INVALID_ID The forum ID does not exist
|
||||
* @throws 1G318/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1L298/4 NO_CONTENT No content was supplied
|
||||
* @throws 1G318/5 INVALID_RATING The rating is not a valid number up to the maximum rating
|
||||
* @throws 2G318/D NO_PERMISSION The authorized user does not have permission to review that image
|
||||
* @return \IPS\gallery\Image\Review
|
||||
*/
|
||||
public function POSTindex()
|
||||
{
|
||||
/* Get topic */
|
||||
/* Get image */
|
||||
try
|
||||
{
|
||||
$image = \IPS\gallery\Image::load( \IPS\Request::i()->image );
|
||||
@@ -108,18 +122,29 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
if ( \IPS\Request::i()->author )
|
||||
if ( $this->member )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author );
|
||||
if ( !$author->member_id )
|
||||
if ( !$image->canReview( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G318/3', 404 );
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G318/D', 403 );
|
||||
}
|
||||
$author = $this->member;
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
if ( \IPS\Request::i()->author )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author );
|
||||
if ( !$author->member_id )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G318/3', 404 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
@@ -142,15 +167,17 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* POST /gallery/reviews/{id}
|
||||
* Edit a review
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author The ID number of the member making the review (0 for guest)
|
||||
* @apiparam int author The ID number of the member making the review (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @apiparam string author_name If author is 0, the guest name that should be used
|
||||
* @apiparam string content The review content as HTML (e.g. "<p>This is a review.</p>")
|
||||
* @apiparam string content The review content as HTML (e.g. "<p>This is a review.</p>"). Will be sanatized for requests using an OAuth Access Token for a particular member; will be saved unaltered for requests made using an API Key or the Client Credentials Grant Type.
|
||||
* @apiparam int hidden 1/0 indicating if the topic should be hidden
|
||||
* @apiparam int rating Star rating
|
||||
* @throws 2L298/5 INVALID_ID The review ID does not exist
|
||||
* @throws 2L298/5 INVALID_ID The review ID does not exist or the authorized user does not have permission to view it
|
||||
* @throws 1G318/B NO_AUTHOR The author ID does not exist
|
||||
* @throws 1G318/A INVALID_RATING The rating is not a valid number up to the maximum rating
|
||||
* @throws 2G318/E NO_PERMISSION The authorized user does not have permission to edit the review
|
||||
* @return \IPS\gallery\Image\Review
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -159,6 +186,14 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
/* Load */
|
||||
$comment = \IPS\gallery\Image\Review::load( $id );
|
||||
if ( $this->member and !$comment->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
if ( $this->member and !$comment->canEdit( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G318/E', 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 ) ) )
|
||||
@@ -186,14 +221,21 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* Deletes a review
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2G318/C INVALID_ID The review ID does not exist
|
||||
* @throws 2G318/C INVALID_ID The review ID does not exist
|
||||
* @throws 2G318/F NO_PERMISSION The authorized user does not have permission to delete the review
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\gallery\Image\Review::load( $id )->delete();
|
||||
$class = $this->class;
|
||||
$object = $class::load( $id );
|
||||
if ( $this->member and !$object->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G318/F', 403 );
|
||||
}
|
||||
$object->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user