Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -79,7 +79,7 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int min_content The minimum amount of posts to be able to view
|
||||
* @apiparam int can_see_others 0|1 Users can see topics posted by other users?
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, reply, attachments) and values as permissions to use (which may be * to grant access to all groups, or an array of group IDs to permit access to)
|
||||
* @apiparam string redirect_url If creating a redirect forum, the URL to redirect too.
|
||||
* @apiparam string redirect_url If creating a redirect forum, the URL to redirect to.
|
||||
* @return \IPS\forums\Forum
|
||||
* @throws 1F363/2 NO_TITLE A title for the forum must be supplied
|
||||
* @throws 1F363/3 NO_REDIRECT_URL No redirect URL supplied.
|
||||
@@ -162,46 +162,51 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
}
|
||||
}
|
||||
|
||||
$forum->parent_id = (int) \IPS\Request::i()->parent ?: -1;
|
||||
|
||||
if ( !isset( \IPS\Request::i()->type ) )
|
||||
if( isset( \IPS\Request::i()->parent ) )
|
||||
{
|
||||
if ( $forum->parent_id === -1 )
|
||||
$forum->parent_id = (int) \IPS\Request::i()->parent ?: -1;
|
||||
|
||||
if ( !isset( \IPS\Request::i()->type ) )
|
||||
{
|
||||
\IPS\Request::i()->type = 'category';
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Request::i()->type = 'normal';
|
||||
}
|
||||
}
|
||||
|
||||
switch( \IPS\Request::i()->type )
|
||||
{
|
||||
case 'category':
|
||||
$forum->sub_can_post = 0;
|
||||
break;
|
||||
|
||||
case 'normal':
|
||||
$forum->sub_can_post = 1;
|
||||
break;
|
||||
|
||||
case 'qa':
|
||||
$forum->forums_bitoptions['bw_enable_answers'] = TRUE;
|
||||
break;
|
||||
|
||||
case 'redirect':
|
||||
if ( !isset( \IPS\Request::i()->redirect_url ) )
|
||||
if ( $forum->parent_id === -1 )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_REDIRECT_URL', '1F363/3', 400 );
|
||||
\IPS\Request::i()->type = 'category';
|
||||
}
|
||||
|
||||
$forum->redirect_on = 1;
|
||||
$forum->redirect_url = \IPS\Request::i()->redirect_url;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \IPS\Api\Exception( 'INVALID_TYPE', '1F363/4', 400 );
|
||||
else
|
||||
{
|
||||
\IPS\Request::i()->type = 'normal';
|
||||
}
|
||||
}
|
||||
|
||||
switch ( \IPS\Request::i()->type )
|
||||
{
|
||||
case 'category':
|
||||
$forum->sub_can_post = 0;
|
||||
break;
|
||||
|
||||
case 'normal':
|
||||
case 'discussion':
|
||||
$forum->sub_can_post = 1;
|
||||
break;
|
||||
|
||||
case 'qa':
|
||||
case 'questions':
|
||||
$forum->forums_bitoptions['bw_enable_answers'] = TRUE;
|
||||
break;
|
||||
|
||||
case 'redirect':
|
||||
if ( !isset( \IPS\Request::i()->redirect_url ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_REDIRECT_URL', '1F363/3', 400 );
|
||||
}
|
||||
|
||||
$forum->redirect_on = 1;
|
||||
$forum->redirect_url = \IPS\Request::i()->redirect_url;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \IPS\Api\Exception( 'INVALID_TYPE', '1F363/4', 400 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->password ) )
|
||||
@@ -231,7 +236,7 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
|
||||
$forum = parent::_createOrUpdate( $forum );
|
||||
|
||||
unset( \IPS\Data\Store::i()->forumsHavePasswords );
|
||||
unset( \IPS\Data\Store::i()->forumsCustomNodes );
|
||||
|
||||
return $forum;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,43 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '1F295/4', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* POST /forums/posts/{id}/react
|
||||
* Add a reaction
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int id ID of the reaction to add
|
||||
* @apiparam int author ID of the member reacting
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @throws 1S425/2 NO_REACTION The reaction ID does not exist
|
||||
* @throws 1S425/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/4 REACT_ERROR Error adding the reaction
|
||||
* @throws 1S425/5 INVALID_ID Object ID does not exist
|
||||
* @note If the author has already reacted to this content, any existing reaction will be removed first
|
||||
*/
|
||||
public function POSTitem_react( $id )
|
||||
{
|
||||
return $this->_reactAdd( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /forums/posts/{id}/react
|
||||
* Delete a reaction
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author ID of the member who reacted
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @throws 1S425/6 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/7 REACT_ERROR Error adding the reaction
|
||||
* @throws 1S425/8 INVALID_ID Object ID does not exist
|
||||
* @note If the author has already reacted to this content, any existing reaction will be removed first
|
||||
*/
|
||||
public function DELETEitem_react( $id )
|
||||
{
|
||||
return $this->_reactRemove( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /forums/posts
|
||||
* Create a post
|
||||
@@ -125,10 +161,12 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
* @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)
|
||||
* @apiparam bool anonymous If 1, the item will be posted anonymously.
|
||||
* @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
|
||||
* @throws 3F295/C NO_ANON_PERMISSION The topic is set for anonymous posting, but the author does not have permission to post anonymously
|
||||
* @return \IPS\forums\Topic\Post
|
||||
*/
|
||||
public function POSTindex()
|
||||
@@ -164,8 +202,24 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
if ( \IPS\Request::i()->author === 0 )
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1F295/2', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check anonymous posting */
|
||||
if ( isset( \IPS\Request::i()->anonymous ) and $author->member_id )
|
||||
{
|
||||
if ( ! $topic->container()->canPostAnonymously( 0, $author ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_ANON_PERMISSION', '3F295/C', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +243,7 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
* @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>"). 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 bool anonymous If 1, the item will be posted anonymously.
|
||||
* @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.
|
||||
@@ -273,4 +328,21 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '1F295/5', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /forums/posts/{id}/report
|
||||
* Reports a post
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author ID of the member reporting
|
||||
* @apiparam int report_type Report type (0 is default and is for letting CMGR team know, more options via core_automatic_moderation_types)
|
||||
* @apiparam string message Optional message
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @throws 1S425/B NO_AUTHOR The author ID does not exist
|
||||
* @throws 1S425/C REPORTED_ALREADY The member has reported this item in the past 24 hours
|
||||
*/
|
||||
public function POSTitem_report( $id )
|
||||
{
|
||||
return $this->_report( $id );
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,7 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
* @throws 1F294/5 NO_TITLE No title was supplied
|
||||
* @throws 1F294/4 NO_POST No post was supplied
|
||||
* @throws 2F294/C NO_PERMISSION The authorized user does not have permission to create a topic in that forum
|
||||
* @throws 3F294/D NO_ANON_PERMISSION The topic is set for anonymous posting, but the author does not have permission to post anonymously
|
||||
* @return \IPS\forums\Topic
|
||||
*/
|
||||
public function POSTindex()
|
||||
@@ -221,8 +222,24 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
if ( \IPS\Request::i()->author === 0 )
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1F294/3', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check anonymous posting */
|
||||
if ( isset( \IPS\Request::i()->anonymous ) and $author->member_id )
|
||||
{
|
||||
if ( ! $forum->canPostAnonymously( 0, $author ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_ANON_PERMISSION', '3F294/D', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +286,7 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
* @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
|
||||
* @throws 1F294/E INVALID_DATE The date is invalid
|
||||
* @return \IPS\forums\Topic
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -337,10 +355,38 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Do we have a date? */
|
||||
if ( isset( \IPS\Request::i()->date ) ) {
|
||||
|
||||
try
|
||||
{
|
||||
$date = new \IPS\DateTime( \IPS\Request::i()->date );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_DATE', '1F294/E', 400 );
|
||||
}
|
||||
|
||||
/* Do we have a first comment? */
|
||||
if ( $commentObj = $topic->firstComment() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$commentClass = $topic::$commentClass;
|
||||
$field = $commentClass::$databaseColumnMap['date'];
|
||||
|
||||
$commentObj->$field = $date->getTimestamp();
|
||||
$commentObj->save();
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Everything else */
|
||||
$this->_createOrUpdate( $topic, 'edit' );
|
||||
|
||||
|
||||
/* Save and return */
|
||||
$topic->save();
|
||||
return new \IPS\Api\Response( 200, $topic->apiOutput( $this->member ) );
|
||||
|
||||
Reference in new issue
Block a user