Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -33,12 +33,14 @@ class _blogs extends \IPS\Node\Api\NodeController
|
||||
* GET /blog/blogs
|
||||
* Get list of blogs
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only blogs that are not disabled and not belonging to a particular club or social group will be included
|
||||
* @apiparam string owners Comma-delimited list of member IDs - if provided, only blogs owned by those members are returned (can be used in conjection with groups or set to 0 to exclude member-created blogs)
|
||||
* @apiparam string groups Comma-delimited list of group IDs - if provided, only blogs owned by those groups are returned (can be used in conjection with members or set to 0 to exclude group blogs)
|
||||
* @apiparam int pinned If 1, only blogs which are pinned are returned, if 0 only not pinned
|
||||
* @apiparam string sortBy What to sort by. Can be 'count_entries' for number of entries, 'last_edate' for last entry date 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\blog\Entry>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -65,6 +67,12 @@ class _blogs extends \IPS\Node\Api\NodeController
|
||||
{
|
||||
$where[] = array( 'blog_pinned=?', intval( \IPS\Request::i()->pinned ) );
|
||||
}
|
||||
|
||||
/* Permission */
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 'blog_disabled=0 AND blog_social_group IS NULL AND blog_club_id IS NULL' );
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'count_entries', 'last_edate' ) ) )
|
||||
@@ -83,7 +91,9 @@ class _blogs extends \IPS\Node\Api\NodeController
|
||||
\IPS\Db::i()->select( '*', 'blog_blogs', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\blog\Blog',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'blog_blogs', $where )->first()
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'blog_blogs', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,7 +102,7 @@ class _blogs extends \IPS\Node\Api\NodeController
|
||||
* Get information about a specific blog
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2B302/1 INVALID_ID The blog ID does not exist
|
||||
* @throws 2B302/1 INVALID_ID The blog ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\blog\Blog
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
@@ -106,9 +116,27 @@ class _blogs extends \IPS\Node\Api\NodeController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @return void
|
||||
* @throws 2B302/2 INVALID_ID The blog ID does not exist or the authorized user does not have permission to view it
|
||||
* @throws 2B302/3 NO_PERMISSION The authorized user does not have permission to delete the blog
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
return $this->_delete( $id );
|
||||
$class = $this->class;
|
||||
|
||||
try
|
||||
{
|
||||
$blog = $this->member ? $class::loadAndCheckPerms( $id ) : $class::load( $id );
|
||||
if ( !$blog->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2B302/3', 404 );
|
||||
}
|
||||
$blog->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2B302/2', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,19 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
|
||||
/**
|
||||
* GET /blog/comments
|
||||
* Get list of comments
|
||||
*
|
||||
* @apiparam string blogs Comma-delimited list of calendar IDs
|
||||
* @note For requests using an OAuth Access Token for a particular member, only comments the authorized user can view will be included, and all comments on draft entries are excluded
|
||||
* @apiparam string blogs Comma-delimited list of blog IDs
|
||||
* @apiparam string authors Comma-delimited list of member IDs - if provided, only topics started by those members are returned
|
||||
* @apiparam int locked If 1, only comments from entries which are locked are returned, if 0 only unlocked
|
||||
* @apiparam int hidden If 1, only comments which are hidden are returned, if 0 only not hidden
|
||||
* @apiparam int pinned If 1, only posts from topics which are pinned are returned, if 0 only not pinned
|
||||
* @apiparam int featured If 1, only comments from entries which are featured are returned, if 0 only not featured
|
||||
* @apiparam int draft If 1, only draft entries are returned, if 0 only published
|
||||
* @apiparam int draft If 1, only draft entries are returned, if 0 only published. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @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\blog\Entry\Comment>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -50,7 +51,11 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
$where = array();
|
||||
|
||||
/* Draft */
|
||||
if ( isset( \IPS\Request::i()->draft ) )
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 'entry_status=?', 'published' );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->draft ) )
|
||||
{
|
||||
$where[] = array( 'entry_status=?', \IPS\Request::i()->draft ? 'draft' : 'published' );
|
||||
}
|
||||
@@ -64,14 +69,24 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* View information about a specific comment
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2B301/1 INVALID_ID The comment ID does not exist
|
||||
* @throws 2B301/1 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\blog\Entry\Comment
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\blog\Entry\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 )
|
||||
{
|
||||
@@ -83,21 +98,23 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* POST /blog/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 entry The ID number of the entry 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 2B301/2 INVALID_ID The comment ID does not exist
|
||||
* @throws 1B301/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1B301/4 NO_CONTENT No content was supplied
|
||||
* @throws 2B301/8 NO_PERMISSION The authorized user does not have permission to comment on that blog entry
|
||||
* @return \IPS\blog\Entry\Comment
|
||||
*/
|
||||
public function POSTindex()
|
||||
{
|
||||
/* Get topic */
|
||||
/* Get entry */
|
||||
try
|
||||
{
|
||||
$entry = \IPS\blog\Entry::load( \IPS\Request::i()->entry );
|
||||
@@ -108,18 +125,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 ( !$entry->canComment( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B301/3', 404 );
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2B301/8', 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', '1B301/3', 404 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
@@ -136,13 +164,15 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* POST /blog/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 2B301/5 INVALID_ID The comment ID does not exist
|
||||
* @throws 2B301/5 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
|
||||
* @throws 1B301/6 NO_AUTHOR The author ID does not exist
|
||||
* @throws 2B301/9 NO_PERMISSION The authorized user does not have permission to edit the comment
|
||||
* @return \IPS\blog\Entry\Comment
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -151,6 +181,14 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
/* Load */
|
||||
$comment = \IPS\blog\Entry\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', '2B301/9', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
try
|
||||
@@ -173,14 +211,21 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* Deletes a comment
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2B301/7 INVALID_ID The comment ID does not exist
|
||||
* @throws 2B301/7 INVALID_ID The comment ID does not exist
|
||||
* @throws 2B301/A NO_PERMISSION The authorized user does not have permission to delete the comment
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\blog\Entry\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', '2B301/A', 403 );
|
||||
}
|
||||
$object->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
* GET /blog/entries
|
||||
* Get list of entries
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only entries that are published and in blogs that are not disabled and not belonging to a particular club or social group will be included
|
||||
* @apiparam string blogs Comma-delimited list of blog IDs
|
||||
* @apiparam string authors Comma-delimited list of member IDs - if provided, only entries started by those members are returned
|
||||
* @apiparam int locked If 1, only entries which are locked are returned, if 0 only unlocked
|
||||
@@ -42,6 +43,7 @@ class _entries 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\blog\Entry>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -49,8 +51,12 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
|
||||
/* Draft */
|
||||
if ( isset( \IPS\Request::i()->draft ) )
|
||||
/* Permission */
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 'entry_status=? AND blog_disabled=0 AND blog_social_group IS NULL AND blog_club_id IS NULL', 'published' );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->draft ) )
|
||||
{
|
||||
$where[] = array( 'entry_status=?', \IPS\Request::i()->draft ? 'draft' : 'published' );
|
||||
}
|
||||
@@ -85,7 +91,8 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int page Page number
|
||||
* @throws 2B300/1 INVALID_ID The entry ID does not exist
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @throws 2B300/1 INVALID_ID The entry ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\blog\Entry\Comment>
|
||||
*/
|
||||
public function GETitem_comments( $id )
|
||||
@@ -104,15 +111,16 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
* POST /blog/entries
|
||||
* Create an entry
|
||||
*
|
||||
* @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 blog The ID number of the blog the entry should be created in
|
||||
* @reqapiparam int author The ID number of the member creating the entry (0 for guest)
|
||||
* @reqapiparam int author The ID number of the member creating the entry (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 title The entry title
|
||||
* @reqapiparam string entry The entry content as HTML (e.g. "<p>This is a blog entry.</p>")
|
||||
* @reqapiparam string entry The entry content as HTML (e.g. "<p>This is a blog entry.</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 bool draft If this is a draft
|
||||
* @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 entry date. If not provided, will use the current date/time
|
||||
* @apiparam string ip_address The IP address that should be stored for the entry/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 entry 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 entry/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 entry 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 entry should be pinned
|
||||
@@ -121,6 +129,7 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
* @throws 1B300/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1B300/4 NO_TITLE No title was supplied
|
||||
* @throws 1B300/5 NO_CONTENT No content was supplied
|
||||
* @throws 1B300/A NO_PERMISSION The authorized user does not have permission to create an entry in that blog
|
||||
* @return \IPS\blog\Entry
|
||||
*/
|
||||
public function POSTindex()
|
||||
@@ -136,17 +145,28 @@ class _entries 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 ( !$blog->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B300/3', 400 );
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '1B300/A', 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', '1B300/3', 400 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a title and a description */
|
||||
@@ -160,29 +180,31 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
return new \IPS\Api\Response( 201, $this->_create( $blog, $author )->apiOutput() );
|
||||
return new \IPS\Api\Response( 201, $this->_create( $blog, $author )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /blog/entries/{id}
|
||||
* Edit a blog entry
|
||||
*
|
||||
* @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 blog The ID number of the blog the entry should be created in
|
||||
* @reqapiparam int author The ID number of the member creating the entry (0 for guest)
|
||||
* @reqapiparam int author The ID number of the member creating the entry (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @reqapiparam string title The entry title
|
||||
* @reqapiparam string entry The entry content as HTML (e.g. "<p>This is a blog entry.</p>")
|
||||
* @reqapiparam string entry The entry content as HTML (e.g. "<p>This is a blog entry.</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 bool draft If this is a draft
|
||||
* @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 entry date. If not provided, will use the current date/time
|
||||
* @apiparam string ip_address The IP address that should be stored for the entry/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 entry 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 entry/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 entry 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 entry should be pinned
|
||||
* @apiparam int featured 1/0 indicating if the entry should be featured
|
||||
* @throws 2B300/6 INVALID_ID The entry ID is invalid
|
||||
* @throws 1B300/7 NO_BLOG The blog ID does not exist
|
||||
* @throws 2B300/6 INVALID_ID The entry ID is invalid or the authorized user does not have permission to view it
|
||||
* @throws 1B300/7 NO_BLOG The blog ID does not exist or the authorized user does not have permission to post in it
|
||||
* @throws 1B300/8 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1B300/B NO_PERMISSION The authorized user does not have permission to edit that blog entry
|
||||
* @return \IPS\blog\Entry
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -190,13 +212,26 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
try
|
||||
{
|
||||
$entry = \IPS\blog\Entry::load( $id );
|
||||
if ( $this->member and !$entry->can( 'read', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
if ( $this->member and !$entry->canEdit( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '1B300/B', 403 );
|
||||
}
|
||||
|
||||
/* New blog */
|
||||
if ( isset( \IPS\Request::i()->blog ) and \IPS\Request::i()->blog != $entry->forum_id )
|
||||
if ( isset( \IPS\Request::i()->blog ) and \IPS\Request::i()->blog != $entry->blog_id and ( !$this->member or $entry->canMove( $this->member ) ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$newBlog = \IPS\blog\Blog::load( \IPS\Request::i()->blog );
|
||||
if ( $this->member and !$newBlog->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
$entry->move( $newBlog );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
@@ -206,7 +241,7 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
|
||||
/* New author */
|
||||
if ( isset( \IPS\Request::i()->author ) )
|
||||
if ( !$this->member and isset( \IPS\Request::i()->author ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -225,11 +260,11 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
|
||||
/* Everything else */
|
||||
$this->_createOrUpdate( $entry );
|
||||
$this->_createOrUpdate( $entry, 'edit' );
|
||||
|
||||
/* Save and return */
|
||||
$entry->save();
|
||||
return new \IPS\Api\Response( 200, $entry->apiOutput() );
|
||||
return new \IPS\Api\Response( 200, $entry->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -241,9 +276,10 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
* Create or update entry
|
||||
*
|
||||
* @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' )
|
||||
{
|
||||
/* Is draft */
|
||||
if ( isset( \IPS\Request::i()->draft ) )
|
||||
@@ -254,11 +290,16 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
/* Content */
|
||||
if ( isset( \IPS\Request::i()->entry ) )
|
||||
{
|
||||
$item->content = \IPS\Request::i()->entry;
|
||||
$entryContents = \IPS\Request::i()->entry;
|
||||
if ( $this->member )
|
||||
{
|
||||
$entryContents = \IPS\Text\Parser::parseStatic( $entryContents, TRUE, NULL, $this->member, 'blog_Entries' );
|
||||
}
|
||||
$item->content = $entryContents;
|
||||
}
|
||||
|
||||
/* Pass up */
|
||||
return parent::_createOrUpdate( $item );
|
||||
return parent::_createOrUpdate( $item, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,14 +307,21 @@ class _entries extends \IPS\Content\Api\ItemController
|
||||
* Delete an entry
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2B300/9 INVALID_ID The entry ID does not exist
|
||||
* @throws 2B300/9 INVALID_ID The entry ID does not exist
|
||||
* @throws 2B300/C NO_PERMISSION The authorized user does not have permission to delete the entry
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\blog\Entry::load( $id )->delete();
|
||||
$item = \IPS\blog\Entry::load( $id );
|
||||
if ( $this->member and !$item->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2B300/C', 404 );
|
||||
}
|
||||
|
||||
$item->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user