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 _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 );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user