Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -27,11 +27,13 @@ class _albums extends \IPS\Api\Controller
|
||||
* GET /gallery/albums
|
||||
* Get list of albums
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only albums the authorized user can view will be included
|
||||
* @apiparam string categories Comma-delimited list of categiry IDs - if provided, only albums in those categories are returned
|
||||
* @apiparam string owners Comma-delimited list of member IDs - if provided, only albums owned by those members are returned
|
||||
* @apiparam string sortBy What to sort by. Can be 'name', 'count_images' for number of images, or do not specify 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\Album>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -85,13 +87,22 @@ class _albums extends \IPS\Api\Controller
|
||||
}
|
||||
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
|
||||
|
||||
/* Get results */
|
||||
if ( $this->member )
|
||||
{
|
||||
$joins = array();
|
||||
$where[] = \IPS\gallery\Album\Item::getItemsWithPermissionWhere( $where, $this->member, $joins );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return new \IPS\Api\PaginatedResponse(
|
||||
200,
|
||||
\IPS\Db::i()->select( '*', 'gallery_albums', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\gallery\Album',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'gallery_albums', $where )->first()
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'gallery_albums', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -100,14 +111,15 @@ class _albums extends \IPS\Api\Controller
|
||||
* Get information about a specific album
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2G315/1 INVALID_ID The album ID does not exist
|
||||
* @throws 2G315/1 INVALID_ID The album ID does not exist or the authorized user does not have permisison to view it
|
||||
* @return \IPS\gallery\Album
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\gallery\Album::load( $id )->apiOutput() );
|
||||
{
|
||||
$album = $this->member ? \IPS\gallery\Album::loadAndCheckPerms( $id, 'view', $this->member ) : \IPS\gallery\Album::load( $id );
|
||||
return new \IPS\Api\Response( 200, $album->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* GET /gallery/comments
|
||||
* Get list of comments
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only comments 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 _comments 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\Comment>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -62,14 +64,24 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* View information about a specific comment
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2L297/1 INVALID_ID The comment ID does not exist
|
||||
* @throws 2L297/1 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\gallery\Image\Comment
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\gallery\Image\Comment::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,21 +93,23 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* POST /gallery/comments
|
||||
* Create a comment
|
||||
*
|
||||
* @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 comment is for
|
||||
* @reqapiparam int author The ID number of the member making the comment (0 for guest)
|
||||
* @reqapiparam int author The ID number of the member making the comment (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 comment content as HTML (e.g. "<p>This is a comment.</p>")
|
||||
* @apiparam datetime date The date/time that should be used for the comment date. If not provided, will use the current date/time
|
||||
* @apiparam string ip_address The IP address that should be stored for the comment. If not provided, will use the IP address from the API request
|
||||
* @reqapiparam string content The comment content as HTML (e.g. "<p>This is a comment.</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 comment 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 comment. 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)
|
||||
* @throws 2G317/3 INVALID_ID The comment ID does not exist
|
||||
* @throws 1G317/4 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1G317/5 NO_CONTENT No content was supplied
|
||||
* @throws 2G317/9 NO_PERMISSION The authorized user does not have permission to comment on that image
|
||||
* @return \IPS\gallery\Image\Comment
|
||||
*/
|
||||
public function POSTindex()
|
||||
{
|
||||
/* Get topic */
|
||||
/* Get image */
|
||||
try
|
||||
{
|
||||
$image = \IPS\gallery\Image::load( \IPS\Request::i()->image );
|
||||
@@ -106,18 +120,29 @@ class _comments 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->canComment( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G317/4', 404 );
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G317/9', 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', '1G317/4', 404 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
@@ -134,13 +159,15 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* POST /gallery/comments/{id}
|
||||
* Edit a comment
|
||||
*
|
||||
* @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 comment (0 for guest)
|
||||
* @apiparam int author The ID number of the member making the comment (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 comment content as HTML (e.g. "<p>This is a comment.</p>")
|
||||
* @apiparam string content The comment content as HTML (e.g. "<p>This is a comment.</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
|
||||
* @throws 2G317/6 INVALID_ID The comment ID does not exist
|
||||
* @throws 2G317/6 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
|
||||
* @throws 1G317/7 NO_AUTHOR The author ID does not exist
|
||||
* @throws 2G317/A NO_PERMISSION The authorized user does not have permission to edit the comment
|
||||
* @return \IPS\gallery\Image\Comment
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -149,6 +176,14 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
/* Load */
|
||||
$comment = \IPS\gallery\Image\Comment::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', '2G317/A', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
try
|
||||
@@ -171,14 +206,21 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* Deletes a comment
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2G317/8 INVALID_ID The comment ID does not exist
|
||||
* @throws 2G317/8 INVALID_ID The comment ID does not exist
|
||||
* @throws 2G317/B NO_PERMISSION The authorized user does not have permission to delete the comment
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\gallery\Image\Comment::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', '2G317/B', 403 );
|
||||
}
|
||||
$object->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* GET /gallery/images
|
||||
* Get list of images
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only images 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 images started by those members are returned
|
||||
@@ -41,6 +42,7 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* @apiparam string sortBy What to sort by. Can be 'date' for creation 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>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -63,7 +65,7 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* View information about a specific image
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2G316/1 INVALID_ID The image ID does not exist
|
||||
* @throws 2G316/1 INVALID_ID The image ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\gallery\Image
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
@@ -82,20 +84,21 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* POST /gallery/images
|
||||
* Upload an image
|
||||
*
|
||||
* @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, locked will only be honoured if the authentictaed user has permission to lock images).
|
||||
* @reqapiparam int album The ID number of the album the image should be created in - not required if category is provided (only provide one or the other)
|
||||
* @reqapiparam int category The ID number of the category the image should be created in - not required if album is provided (only provide one or the other)
|
||||
* @reqapiparam int author The ID number of the member uploading the image (0 for guest)
|
||||
* @reqapiparam int author The ID number of the member uploading the image (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
|
||||
* @reqapiparam string caption The image caption
|
||||
* @reqapiparam string filename The image filename (e.g. 'image.png')
|
||||
* @reqapiparam string image The base64 encoded image contents
|
||||
* @apiparam string description The description as HTML (e.g. "<p>This is an image.</p>")
|
||||
* @apiparam string description The description as HTML (e.g. "<p>This is an image.</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 string copyright The copyright
|
||||
* @apiparam string credit The credit information
|
||||
* @apiparam int gpsShow If the image contains the location in it's EXIF data, 1/0 indicating if a map should be shown (defaults to 1)
|
||||
* @apiparam string prefix Prefix tag
|
||||
* @apiparam string tags Comma-separated list of tags (do not include prefix)
|
||||
* @apiparam datetime date The date/time that should be used for the image post date. If not provided, will use the current date/time
|
||||
* @apiparam string ip_address The IP address that should be stored for the image. If not provided, will use the IP address from the API request
|
||||
* @apiparam datetime date The date/time that should be used for the image post 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 image. 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 locked 1/0 indicating if the image should be locked
|
||||
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
|
||||
* @apiparam int pinned 1/0 indicating if the image should be locked
|
||||
@@ -105,6 +108,8 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* @throws 1G316/4 NO_CAPTION No caption was supplied
|
||||
* @throws 1G316/5 NO_FILENAME No filename was supplied
|
||||
* @throws 1G316/6 NO_IMAGE The image was invalid
|
||||
* @throws 2G316/D NO_PERMISSION The authorized user does not have permission to create an image in that category/album
|
||||
* @throws 1G316/E IMAGE_TOO_BIG The image exceeds the filesize the authorized user can upload
|
||||
* @return \IPS\gallery\Image
|
||||
*/
|
||||
public function POSTindex()
|
||||
@@ -135,17 +140,35 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
if ( \IPS\Request::i()->author )
|
||||
if ( $this->member )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author );
|
||||
if ( !$author->member_id )
|
||||
if ( isset( \IPS\Request::i()->album ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G316/3', 400 );
|
||||
if ( !$album->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G316/D', 403 );
|
||||
}
|
||||
}
|
||||
elseif ( !$category->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G316/D', 403 );
|
||||
}
|
||||
$author = $this->member;
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
if ( \IPS\Request::i()->author )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author );
|
||||
if ( !$author->member_id )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G316/3', 400 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a caption and a filename */
|
||||
@@ -160,6 +183,10 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
|
||||
/* Check it's a valid image */
|
||||
$imageContents = base64_decode( \IPS\Request::i()->image );
|
||||
if ( $this->member and $this->member->group['g_max_upload'] and \strlen( $imageContents ) > $this->member->group['g_max_upload'] * 1024 )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'IMAGE_TOO_BIG', '1G316/E', 400 );
|
||||
}
|
||||
try
|
||||
{
|
||||
$imageObject = \IPS\Image::create( $imageContents );
|
||||
@@ -199,32 +226,34 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
$image->save();
|
||||
|
||||
/* Output */
|
||||
return new \IPS\Api\Response( 201, $image->apiOutput() );
|
||||
return new \IPS\Api\Response( 201, $image->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /gallery/images/{id}
|
||||
* Edit an image
|
||||
*
|
||||
* @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, locked will only be honoured if the authentictaed user has permission to lock topics).
|
||||
* @apiparam int album The ID number of the album (only provide this or category to move image)
|
||||
* @apiparam int category The ID number of the category (only provide this or category to move image)
|
||||
* @apiparam int author The ID number of the member uploading the image (0 for guest)
|
||||
* @apiparam int author The ID number of the member uploading the image (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @apiparam string caption The image caption
|
||||
* @apiparam string description The description as HTML (e.g. "<p>This is an image.</p>")
|
||||
* @apiparam string description The description as HTML (e.g. "<p>This is an image.</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 string copyright The copyright
|
||||
* @apiparam string credit The credit information
|
||||
* @apiparam int gpsShow If the image contains the location in it's EXIF data, 1/0 indicating if a map should be shown (defaults to 1)
|
||||
* @apiparam string prefix Prefix tag
|
||||
* @apiparam string tags Comma-separated list of tags (do not include prefix)
|
||||
* @apiparam datetime date The date/time that should be used for the image post date. If not provided, will use the current date/time
|
||||
* @apiparam string ip_address The IP address that should be stored for the image. If not provided, will use the IP address from the API request
|
||||
* @apiparam datetime date The date/time that should be used for the image post 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 image. 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 locked 1/0 indicating if the image should be locked
|
||||
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
|
||||
* @apiparam int pinned 1/0 indicating if the image should be locked
|
||||
* @apiparam int featured 1/0 indicating if the image should be featured
|
||||
* @throws 2G316/7 INVALID_ID The image ID is invalid
|
||||
* @throws 1G316/8 NO_CATEGORY_OR_ALBUM The category or album does not exist
|
||||
* @throws 2G316/7 INVALID_ID The image ID is invalid or the authorized user does not have permission to view it
|
||||
* @throws 1G316/8 NO_CATEGORY_OR_ALBUM The category or album does not exist or the authorized user does not have permission to post in it
|
||||
* @throws 1G316/9 NO_AUTHOR The author ID does not exist
|
||||
* @throws 2G316/F NO_PERMISSION The authorized user does not have permission to edit the image
|
||||
* @return \IPS\gallery\Image
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -232,28 +261,49 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
try
|
||||
{
|
||||
$image = \IPS\gallery\Image::load( $id );
|
||||
if ( $this->member and !$image->can( 'read', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
if ( $this->member and !$image->canEdit( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G316/FD', 403 );
|
||||
}
|
||||
|
||||
/* New category or album */
|
||||
try
|
||||
if ( !$this->member or $image->canMove( $this->member ) )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->album ) and \IPS\Request::i()->album != $image->album_id )
|
||||
try
|
||||
{
|
||||
$newAlbum = \IPS\gallery\Album::load( \IPS\Request::i()->album );
|
||||
$image->move( $newAlbum );
|
||||
if ( isset( \IPS\Request::i()->album ) and \IPS\Request::i()->album != $image->album_id )
|
||||
{
|
||||
$newAlbum = \IPS\gallery\Album::load( \IPS\Request::i()->album );
|
||||
if ( $this->member and !$newAlbum->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
$image->move( $newAlbum );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->category ) and \IPS\Request::i()->category != $image->category_id )
|
||||
{
|
||||
$newCategory = \IPS\gallery\Category::load( \IPS\Request::i()->category );
|
||||
if ( $this->member and !$newCategory->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
$image->move( $newCategory );
|
||||
}
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->category ) and \IPS\Request::i()->category != $image->category_id )
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$newCategory = \IPS\gallery\Category::load( \IPS\Request::i()->category );
|
||||
$image->move( $newCategory );
|
||||
throw new \IPS\Api\Exception( 'NO_CATEGORY_OR_ALBUM', '1G316/8', 400 );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_CATEGORY_OR_ALBUM', '1G316/8', 400 );
|
||||
}
|
||||
|
||||
/* New author */
|
||||
if ( isset( \IPS\Request::i()->author ) )
|
||||
if ( !$this->member and isset( \IPS\Request::i()->author ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -272,11 +322,11 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
|
||||
/* Everything else */
|
||||
$this->_createOrUpdate( $image );
|
||||
$this->_createOrUpdate( $image, 'edit' );
|
||||
|
||||
/* Save and return */
|
||||
$image->save();
|
||||
return new \IPS\Api\Response( 200, $image->apiOutput() );
|
||||
return new \IPS\Api\Response( 200, $image->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -292,7 +342,8 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* @apiparam int hidden If 1, only comments which are hidden are returned, if 0 only not hidden
|
||||
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
|
||||
* @apiparam int page Page number
|
||||
* @throws 2G316/A INVALID_ID The image ID does not exist
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @throws 2G316/A INVALID_ID The image ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Image\Comment>
|
||||
*/
|
||||
public function GETitem_comments( $id )
|
||||
@@ -315,7 +366,8 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* @apiparam int hidden If 1, only comments which are hidden are returned, if 0 only not hidden
|
||||
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
|
||||
* @apiparam int page Page number
|
||||
* @throws 2G316/B INVALID_ID The image ID does not exist
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @throws 2G316/B INVALID_ID The image ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Image\Review>
|
||||
*/
|
||||
public function GETitem_reviews( $id )
|
||||
@@ -334,9 +386,10 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* Create or update image
|
||||
*
|
||||
* @param \IPS\Content\Item $item The item
|
||||
* @param string $type add or edit
|
||||
* @return \IPS\Content\Item
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\Content\Item $item )
|
||||
protected function _createOrUpdate( \IPS\Content\Item $item, $type='add' )
|
||||
{
|
||||
/* Album */
|
||||
if ( isset( \IPS\Request::i()->album ) and !$item->id )
|
||||
@@ -353,7 +406,12 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
/* Description */
|
||||
if ( isset( \IPS\Request::i()->description ) )
|
||||
{
|
||||
$item->description = \IPS\Request::i()->description;
|
||||
$descriptionContents = \IPS\Request::i()->description;
|
||||
if ( $this->member )
|
||||
{
|
||||
$descriptionContents = \IPS\Text\Parser::parseStatic( $descriptionContents, TRUE, NULL, $this->member, 'gallery_Images' );
|
||||
}
|
||||
$item->description = $descriptionContents;
|
||||
}
|
||||
|
||||
/* Copyright */
|
||||
@@ -375,7 +433,7 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
|
||||
/* Pass up */
|
||||
return parent::_createOrUpdate( $item );
|
||||
return parent::_createOrUpdate( $item, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,14 +441,21 @@ class _images extends \IPS\Content\Api\ItemController
|
||||
* Delete an image
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2G316/C INVALID_ID The image ID does not exist
|
||||
* @throws 2G316/C INVALID_ID The image ID does not exist
|
||||
* @throws 2G316/G NO_PERMISSION The authorized user does not have permission to delete the image
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\gallery\Image::load( $id )->delete();
|
||||
$item = \IPS\gallery\Image::load( $id );
|
||||
if ( $this->member and !$item->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2G316/G', 404 );
|
||||
}
|
||||
|
||||
$item->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
|
||||
@@ -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