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

+20 -9
View File
@@ -32,6 +32,9 @@ class _forums extends \IPS\Node\Api\NodeController
* GET /forums/forums
* Get list of forums
*
* @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 forums the authorized user can view will be included
* @return \IPS\Api\PaginatedResponse<IPS\forums\Forum>
*/
public function GETindex()
@@ -45,19 +48,26 @@ class _forums extends \IPS\Node\Api\NodeController
* Get specific forum
*
* @param int $id ID Number
*
* @return \IPS\Api\PaginatedResponse<IPS\forums\Forum>
* @throws 1F363/1 INVALID_ID The forum does not exist or the authorized user does not have permission to view it
* @return \IPS\forums\Forum
*/
public function GETitem( $id )
{
/* Return */
return $this->_view( $id );
try
{
return $this->_view( $id );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1F363/1', 404 );
}
}
/**
* POST /forums/forums
* Create a forum
*
* @apiclientonly
* @reqapiparam string title The forum title
* @apiparam string description The forum description
* @apiparam string type normal|qa|redirect|category
@@ -71,13 +81,14 @@ class _forums extends \IPS\Node\Api\NodeController
*/
public function POSTindex()
{
return $this->_create();
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
}
/**
* POST /forums/forums/{id}
* Edit a forum
*
* @apiclientonly
* @reqapiparam string title The forum title
* @apiparam string description The forum description
* @apiparam string type normal|qa|redirect|category
@@ -91,17 +102,17 @@ class _forums extends \IPS\Node\Api\NodeController
*/
public function POSTitem( $id )
{
$class = static::$class;
$class = $this->class;
$forum = $class::load( $id );
$forum = $this->_createOrUpdate( $forum );
return $forum;
return new \IPS\Api\Response( 201, $this->_createOrUpdate( $forum )->apiOutput( $this->member ) );
}
/**
* DELETE /forums/forums/{id}
* Delete a forum
*
* @apiclientonly
* @param int $id ID Number
* @return void
*/
+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 );
}
+71 -32
View File
@@ -32,6 +32,7 @@ class _topics extends \IPS\Content\Api\ItemController
* GET /forums/topics
* Get list of topics
*
* @note For requests using an OAuth Access Token for a particular member, only topics 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 topics started by those members are returned
* @apiparam int hasBestAnswer If 1, only topics with a best answer are returned, if 0 only without
@@ -44,6 +45,7 @@ class _topics extends \IPS\Content\Api\ItemController
* @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>
*/
public function GETindex()
@@ -109,7 +111,8 @@ class _topics extends \IPS\Content\Api\ItemController
* @apiparam int hidden If 1, only posts 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 1F294/1 INVALID_ID The topic ID does not exist
* @apiparam int perPage Number of results per page - defaults to 25
* @throws 1F294/1 INVALID_ID The topic ID does not exist or the authorized user does not have permission to view it
* @return \IPS\Api\PaginatedResponse<IPS\forums\Topic\Post>
*/
public function GETitem_posts( $id )
@@ -128,9 +131,10 @@ class _topics extends \IPS\Content\Api\ItemController
* Create or update topic
*
* @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' )
{
/* Open/Close time */
if ( \IPS\Request::i()->open_time )
@@ -143,32 +147,34 @@ class _topics extends \IPS\Content\Api\ItemController
}
/* Pass up */
return parent::_createOrUpdate( $item );
return parent::_createOrUpdate( $item, $type );
}
/**
* POST /forums/topics
* Create a topic
*
* @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).
* @reqapiparam int forum The ID number of the forum the topic should be created in
* @reqapiparam int author The ID number of the member creating the topic (0 for guest)
* @apiparam int author The ID number of the member creating the topic (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 title The topic title
* @reqapiparam string post The post content as HTML (e.g. "<p>This is a post.</p>")
* @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 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 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
* @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 locked 1/0 indicating if the topic should be locked
* @apiparam datetime open_time When the topic should be unlocked from
* @apiparam datetime close_time When the topic should be locked from
* @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 topic should be pinned
* @apiparam int featured 1/0 indicating if the topic should be featured
* @throws 1F294/2 NO_FORUM The forum ID does not exist
* @throws 1F294/3 NO_AUTHOR The author ID does not exist
* @throws 1F294/5 NO_TITLE No title was supplied
* @throws 1F294/4 NO_POST No post was supplied
* @throws 1F294/2 NO_FORUM The forum ID does not exist
* @throws 1F294/3 NO_AUTHOR The author ID does not exist
* @throws 1F294/5 NO_TITLE No title was supplied
* @throws 1F294/4 NO_POST No post was supplied
* @throws 2F294/9 NO_PERMISSION The authorized user does not have permission to create a topic in that forum
* @return \IPS\forums\Topic
*/
public function POSTindex()
@@ -184,18 +190,29 @@ class _topics 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 ( !$forum->can( 'add', $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1F294/3', 400 );
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/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', '1F294/3', 400 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
}
/* Check we have a title and a post */
@@ -209,31 +226,33 @@ class _topics extends \IPS\Content\Api\ItemController
}
/* Do it */
return new \IPS\Api\Response( 201, $this->_create( $forum, $author )->apiOutput() );
return new \IPS\Api\Response( 201, $this->_create( $forum, $author )->apiOutput( $this->member ) );
}
/**
* POST /forums/topics/{id}
* Edit a topic
*
* @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 forum The ID number of the forum the topic should be created in
* @apiparam int author The ID number of the member creating the topic (0 for guest)
* @apiparam int author The ID number of the member creating the topic (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 title The topic title
* @apiparam string post The post content as HTML (e.g. "<p>This is a post.</p>")
* @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 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 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
* @apiparam datetime date The date/time that should be used for the topic/post post date. 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. Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam int locked 1/0 indicating if the topic should be locked
* @apiparam datetime open_time When the topic should be unlocked from
* @apiparam datetime close_time When the topic should be locked from
* @apiparam int hidden 1/0 indicating if the topic should be hidden
* @apiparam int pinned 1/0 indicating if the topic should be pinned
* @apiparam int featured 1/0 indicating if the topic should be featured
* @throws 2F294/6 INVALID_ID The topic ID does not exist
* @throws 1F294/7 NO_FORUM The forum ID does not exist
* @throws 1F294/8 NO_AUTHOR The author ID does not exist
* @throws 2F294/6 INVALID_ID The topic ID does not exist or the authorized user does not have permission to view it
* @throws 1F294/7 NO_FORUM The forum ID does not exist or the authorized user does not have permission to post in it
* @throws 1F294/8 NO_AUTHOR The author ID does not exist
* @throws 2F294/A NO_PERMISSION The authorized user does not have permission to edit the topic
* @return \IPS\forums\Topic
*/
public function POSTitem( $id )
@@ -241,13 +260,26 @@ class _topics extends \IPS\Content\Api\ItemController
try
{
$topic = \IPS\forums\Topic::load( $id );
if ( $this->member and !$topic->can( 'read', $this->member ) )
{
throw new \OutOfRangeException;
}
if ( $this->member and !$topic->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/A', 403 );
}
/* New forum */
if ( isset( \IPS\Request::i()->forum ) and \IPS\Request::i()->forum != $topic->forum_id )
if ( isset( \IPS\Request::i()->forum ) and \IPS\Request::i()->forum != $topic->forum_id and ( !$this->member or $topic->canMove( $this->member ) ) )
{
try
{
$newForum = \IPS\forums\Forum::load( \IPS\Request::i()->forum );
if ( $this->member and !$newForum->can( 'add', $this->member ) )
{
throw new \OutOfRangeException;
}
$topic->move( $newForum );
}
catch ( \OutOfRangeException $e )
@@ -257,7 +289,7 @@ class _topics extends \IPS\Content\Api\ItemController
}
/* New author */
if ( isset( \IPS\Request::i()->author ) )
if ( !$this->member and isset( \IPS\Request::i()->author ) )
{
/* Just renaming the guest */
if ( !$topic->starter_id and ( !isset( \IPS\Request::i()->author ) or !\IPS\Request::i()->author ) and isset( \IPS\Request::i()->author_name ) )
@@ -291,11 +323,11 @@ class _topics extends \IPS\Content\Api\ItemController
}
/* Everything else */
$this->_createOrUpdate( $topic );
$this->_createOrUpdate( $topic, 'edit' );
/* Save and return */
$topic->save();
return new \IPS\Api\Response( 200, $topic->apiOutput() );
return new \IPS\Api\Response( 200, $topic->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
{
@@ -307,15 +339,22 @@ class _topics extends \IPS\Content\Api\ItemController
* DELETE /forums/topics/{id}
* Delete a topic
*
* @param int $id ID Number
* @throws 1F294/5 INVALID_ID The topic ID does not exist
* @param int $id ID Number
* @throws 1F294/5 INVALID_ID The topic ID does not exist
* @throws 2F294/B NO_PERMISSION The authorized user does not have permission to delete the topic
* @return void
*/
public function DELETEitem( $id )
{
try
{
\IPS\forums\Topic::load( $id )->delete();
$item = \IPS\forums\Topic::load( $id );
if ( $this->member and !$item->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/B', 404 );
}
$item->delete();
return new \IPS\Api\Response( 200, NULL );
}