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 _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