Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+62 -24
View File
@@ -32,6 +32,7 @@ class _posts extends \IPS\Content\Api\CommentController
* GET /forums/posts
* Get list of posts
*
* @note For requests using an OAuth Access Token for a particular member, only posts the authorized user can view will be included
* @apiparam string forums Comma-delimited list of forum IDs
* @apiparam string authors Comma-delimited list of member IDs - if provided, only posts by those members are returned
* @apiparam int hasBestAnswer If 1, only posts from topics with a best answer are returned, if 0 only without
@@ -44,6 +45,7 @@ class _posts 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\forums\Topic\Post>
*/
public function GETindex()
@@ -86,14 +88,24 @@ class _posts extends \IPS\Content\Api\CommentController
* View information about a specific post
*
* @param int $id ID Number
* @throws 1F295/4 INVALID_ID The post ID does not exist
* @throws 1F295/4 INVALID_ID The post ID does not exist or the authorized user does not have permission to view it
* @return \IPS\forums\Topic\Post
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\forums\Topic\Post::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 )
{
@@ -105,16 +117,18 @@ class _posts extends \IPS\Content\Api\CommentController
* POST /forums/posts
* Create a post
*
* @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 topic The ID number of the topic the post should be created in
* @reqapiparam int author The ID number of the member making the post (0 for guest)
* @reqapiparam int author The ID number of the member making the post (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 post The post content as HTML (e.g. "<p>This is a post.</p>")
* @apiparam datetime date The date/time that should be used for the topic/post post date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the topic/post. If not provided, will use the IP address from the API request
* @reqapiparam string post The post content as HTML (e.g. "<p>This is a post.</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 topic/post 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 topic/post. 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 1F295/1 NO_TOPIC The forum ID does not exist
* @throws 1F295/1 NO_TOPIC The topic ID does not exist
* @throws 1F295/2 NO_AUTHOR The author ID does not exist
* @throws 1F295/3 NO_POST No post was supplied
* @throws 2F294/A NO_PERMISSION The authorized user does not have permission to reply to that topic
* @return \IPS\forums\Topic\Post
*/
public function POSTindex()
@@ -130,18 +144,29 @@ class _posts 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 ( !$topic->canComment( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1F295/2', 403 );
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/A', 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', '1F295/2', 403 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
}
/* Check we have a post */
@@ -158,16 +183,17 @@ class _posts extends \IPS\Content\Api\CommentController
* POST /forums/posts/{id}
* Edit a post
*
* @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 post (0 for guest)
* @apiparam int author The ID number of the member making the post (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 post The post content as HTML (e.g. "<p>This is a post.</p>")
* @apiparam int hidden 1/0 indicating if the topic should be hidden
* @throws 2F295/6 INVALID_ID The post ID does not exist
* @throws 2F295/7 NO_AUTHOR The author ID does not exist
* @throws 2F295/7 NO_AUTHOR The author ID does not exist
* @apiparam string post The post content as HTML (e.g. "<p>This is a post.</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 2F295/6 INVALID_ID The post ID does not exist or the authorized user does not have permission to view it
* @throws 2F295/7 NO_AUTHOR The author ID does not exist
* @throws 1F295/8 CANNOT_HIDE_FIRST_POST You cannot hide or unhide the first post in a topic. Hide/unhide the topic itself instead.
* @throws 1F295/9 CANNOT_AUTHOR_FIRST_POST You cannot change the author for the first post in a topic. Change the author on the topic itself instead.
* @throws 2F295/A NO_PERMISSION The authorized user does not have permission to edit the post
* @return \IPS\forums\Topic\Post
*/
public function POSTitem( $id )
@@ -176,6 +202,14 @@ class _posts extends \IPS\Content\Api\CommentController
{
/* Load */
$post = \IPS\forums\Topic\Post::load( $id );
if ( $this->member and !$post->canView( $this->member ) )
{
throw new \OutOfRangeException;
}
if ( $this->member and !$post->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F295/A', 403 );
}
/* Check */
if ( $post->isFirst() )
@@ -213,20 +247,24 @@ class _posts extends \IPS\Content\Api\CommentController
* @param int $id ID Number
* @throws 1F295/5 INVALID_ID The post ID does not exist
* @throws 1F295/B CANNOT_DELETE_FIRST_POST You cannot delete the first post in a topic. Delete the topic itself instead.
* @throws 2F295/B NO_PERMISSION The authorized user does not have permission to delete the post
* @return void
*/
public function DELETEitem( $id )
{
try
{
$post = \IPS\forums\Topic\Post::load( $id );
if ( $post->isFirst() )
$class = $this->class;
$object = $class::load( $id );
if ( $object->isFirst() )
{
throw new \IPS\Api\Exception( 'CANNOT_DELETE_FIRST_POST', '1F295/B', 403 );
}
$post->delete();
if ( $this->member and !$object->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F295/B', 403 );
}
$object->delete();
return new \IPS\Api\Response( 200, NULL );
}