Version 4.7.0

This commit is contained in:
Neo committed 2025-12-19 16:00:35 -08:00
1 parent 517a5e1f70
commit 8ba7d43898
1933 files changed
+65613 -11332

No files matched your search

+114 -2
View File
@@ -164,6 +164,7 @@ class _comments extends \IPS\Content\Api\CommentController
* @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)
* @apiparam bool anonymous If 1, the item will be posted anonymously.
* @throws 2T311/4 INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @throws 2T311/5 INVALID_ID The comment ID does not exist
* @throws 1T311/6 NO_AUTHOR The author ID does not exist
@@ -220,8 +221,15 @@ class _comments 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', '1T311/6', 400 );
}
}
}
@@ -246,6 +254,7 @@ class _comments extends \IPS\Content\Api\CommentController
* @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>"). 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 2T311/7 INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @throws 2T311/8 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
* @throws 1T311/9 NO_AUTHOR The author ID does not exist
@@ -346,4 +355,107 @@ class _comments extends \IPS\Content\Api\CommentController
throw new \IPS\Api\Exception( 'INVALID_ID', '2T311/B', 404 );
}
}
/**
* POST /cms/comments/{database_id}/{comment_id}/react
* Add a reaction
*
* @param int $database Database ID
* @param int $comment Comment ID
* @apiparam int id ID of the reaction to add
* @apiparam int author ID of the member reacting
* @return \IPS\cms\Records\Comment
* @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
* @throws 2T311/C INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @note If the author has already reacted to this content, any existing reaction will be removed first
*/
public function POSTitem_react( $database, $comment )
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records\Comment' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '2T311/C', 404 );
}
return $this->_reactAdd( $comment );
}
/**
* DELETE /cms/comments/{database_id}/{comment_id}/react
* Delete a reaction
*
* @param int $database Database ID
* @param int $comment Comment ID
* @apiparam int author ID of the member who reacted
* @return \IPS\cms\Records\Comment
* @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
* @throws 2T311/D INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @note If the author has already reacted to this content, any existing reaction will be removed first
*/
public function DELETEitem_react( $database, $comment )
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records\Comment' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '2T311/D', 404 );
}
return $this->_reactRemove( $comment );
}
/**
* POST /cms/comments/{database_id}/{comment_id}/report
* Reports a post
*
* @param int $database Database ID
* @param int $comment Comment ID
* @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\cms\Records\Comment
* @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( $database, $comment )
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records\Comment' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '2T311/D', 404 );
}
return $this->_report( $comment );
}
}
+261 -7
View File
@@ -162,7 +162,7 @@ class _records extends \IPS\Content\Api\ItemController
* @param int $database Database ID Number
* @reqapiparam int category The ID number of the category the record should be created in. If the database does not use categories, this is not required
* @reqapiparam int author The ID number of the member creating the record (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 object fields Field values. Keys should be the field ID, and the value should be the value. For requests using an OAuth Access Token for a particular member, values will be sanatised where necessary. For requests made using an API Key or the Client Credentials Grant Type values will be saved unchanged.
* @reqapiparam object fields Field values. Keys should be the field ID, and the value should be the value. For fields of the Upload type, the type of the value must also be an object itself, with each key set as the filename and the value set as the raw file contents. For requests using an OAuth Access Token for a particular member, values will be sanatised where necessary. For requests made using an API Key or the Client Credentials Grant Type values will be saved unchanged.
* @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 record date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member.
@@ -171,11 +171,18 @@ class _records extends \IPS\Content\Api\ItemController
* @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 record should be pinned
* @apiparam int featured 1/0 indicating if the record should be featured
* @apiparam bool anonymous If 1, the item will be posted anonymously.
* @throws 2T306/4 INVALID_DATABASE The database ID does not exist
* @throws 1T306/5 NO_CATEGORY The category ID does not exist
* @throws 1T306/6 NO_AUTHOR The author ID does not exist
* @throws 2T306/G NO_PERMISSION The authorized user does not have permission to create a record in that category
* @throws 1T306/D TITLE_CONTENT_REQUIRED No title or content fields were supplied
* @throws 1S306/E UPLOAD_FIELD_NOT_OBJECT Field of type Upload was supplied without being set as an object
* @throws 1T306/F UPLOAD_FIELD_NO_FILES Field of type Upload was supplied without any files attached
* @throws 1T306/G UPLOAD_FIELD_MULTIPLE_NOT_ALLOWED Field of type Upload and a maximum of 1 file was supplied with multiple files
* @throws 1T306/H UPLOAD_FIELD_IMAGE_NOT_SUPPORTED Field of type Upload was supplied with an image was of an unsupported extension
* @throws 1T306/I UPLOAD_FIELD_IMAGES_ONLY Field of type Upload set to be image only was supplied with a non-image attachment
* @throws 1T306/J UPLOAD_FIELD_EXTENSION_NOT_ALLOWED Field of type Upload was supplied with one or more attachments of a non-supported file extension
* @return \IPS\cms\Records
*/
public function POSTindex( $database )
@@ -231,7 +238,15 @@ class _records extends \IPS\Content\Api\ItemController
}
else
{
$author = new \IPS\Member;
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', '1T306/6', 400 );
}
}
}
@@ -273,7 +288,7 @@ class _records extends \IPS\Content\Api\ItemController
* @param int $record Record ID Number
* @apiparam int category The ID number of the category the record should be created in. If the database does not use categories, this is not required
* @apiparam int author The ID number of the member creating the record (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
* @reqapiparam object fields Field values. Keys should be the field ID, and the value should be the value. For requests using an OAuth Access Token for a particular member, values will be sanatised where necessary. For requests made using an API Key or the Client Credentials Grant Type values will be saved unchanged.
* @reqapiparam object fields Field values. Keys should be the field ID, and the value should be the value. For fields of the Upload type, the type of the value must also be an object itself, with each key set as the filename and the value set as the raw file contents. For requests using an OAuth Access Token for a particular member, values will be sanatised where necessary. For requests made using an API Key or the Client Credentials Grant Type values will be saved unchanged.
* @apiparam string prefix Prefix tag
* @apiparam string tags Comma-separated list of tags (do not include prefix)
* @apiparam string ip_address The IP address that should be stored for the record. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member.
@@ -281,11 +296,18 @@ class _records extends \IPS\Content\Api\ItemController
* @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 record should be pinned
* @apiparam int featured 1/0 indicating if the record should be featured
* @apiparam bool anonymous If 1, the item will be posted anonymously.
* @throws 2T306/9 INVALID_DATABASE The database ID does not exist
* @throws 2T306/6 INVALID_ID The record ID is invalid or the authorized user does not have permission to view it
* @throws 1T306/7 NO_CATEGORY The category ID does not exist or the authorized user does not have permission to post in it
* @throws 1T306/8 NO_AUTHOR The author ID does not exist
* @throws 2T306/H NO_PERMISSION The authorized user does not have permission to edit the record
* @throws 1S306/E UPLOAD_FIELD_NOT_OBJECT Field of type Upload was supplied without being set as an object
* @throws 1T306/F UPLOAD_FIELD_NO_FILES Field of type Upload was supplied without any files attached
* @throws 1T306/G UPLOAD_FIELD_MULTIPLE_NOT_ALLOWED Field of type Upload and a maximum of 1 file was supplied with multiple files
* @throws 1T306/H UPLOAD_FIELD_IMAGE_NOT_SUPPORTED Field of type Upload was supplied with an image was of an unsupported extension
* @throws 1T306/I UPLOAD_FIELD_IMAGES_ONLY Field of type Upload set to be image only was supplied with a non-image attachment
* @throws 1T306/J UPLOAD_FIELD_EXTENSION_NOT_ALLOWED Field of type Upload was supplied with one or more attachments of a non-supported file extension
* @return \IPS\cms\Records
*/
public function POSTitem( $database, $record )
@@ -389,6 +411,7 @@ class _records extends \IPS\Content\Api\ItemController
*/
protected function _createOrUpdate( \IPS\Content\Item $item, $type='add' )
{
$thumbImages = array();
/* Set field values */
if ( isset( \IPS\Request::i()->fields ) )
{
@@ -400,12 +423,92 @@ class _records extends \IPS\Content\Api\ItemController
if ( !$this->member or $field->can( $type, $this->member ) )
{
$key = "field_{$field->_id}";
$value = \IPS\Request::i()->fields[ $field->id ];
if ( $field->type === 'Editor' and $this->member )
{
$value = \IPS\Text\Parser::parseStatic( $value, TRUE, NULL, $this->member, 'cms_Records' );
}
elseif ( $field->type === 'Upload' )
{
$multiple = $field->is_multiple;
$imageOnly = ( isset( $field->extra[ 'type' ] ) AND $field->extra[ 'type' ] === 'image' );
$extensions = \is_array( $field->allowed_extensions ) ? $field->allowed_extensions : array();
/* Did they meet the api parameter type requirement (the field must be an object) */
if ( !\is_array( \IPS\Request::i()->fields[ $field->id ] ) )
{
throw new \IPS\Api\Exception( 'UPLOAD_FIELD_NOT_OBJECT', '1S306/E', 400 );
}
/* Are we actually uploading files? */
if ( empty( \IPS\Request::i()->fields[ $field->id ] ) )
{
throw new \IPS\Api\Exception( 'UPLOAD_FIELD_NO_FILES', '1T306/F', 400 );
}
/* Can we upload more than one file? */
if ( !$multiple AND ( \count( \IPS\Request::i()->fields[ $field->id ] ) > 1 ) )
{
throw new \IPS\Api\Exception( 'UPLOAD_FIELD_MULTIPLE_NOT_ALLOWED', '1T306/G', 400 );
}
/* Does each file meet the criteria? */
$files = array();
foreach ( array_keys( \IPS\Request::i()->fields[ $field->id ] ) as $name )
{
$files[] = $name;
$components = explode( '.', $name );
$extension = array_pop( $components );
/* Can we upload a non image? */
if ( $imageOnly )
{
/* Is the image type supported? */
if ( !\in_array( $extension, \IPS\Image::supportedExtensions() ) )
{
throw new \IPS\Api\Exception( 'UPLOAD_FIELD_IMAGE_NOT_SUPPORTED', '1T306/H', 400 );
}
/* Is there a max image dimensions specified? */
$maxSize = ( isset( $field->extra[ 'maxsize' ] ) AND \is_array( $field->extra[ 'maxsize' ] ) ) ? $field->extra[ 'maxsize' ] : array( 0, 0 );
try
{
/* Is it valid image data? */
$image = \IPS\Image::create( $_POST[ 'fields' ][ $field->id ][ $name ] );
/* Resize if too large */
$image->resizeToMax( (int) $maxSize[0] ?: NULL, (int) $maxSize[1] ?: NULL );
$_POST[ 'fields' ][ $field->id ][ $name ] = (string) $image;
}
catch ( \InvalidArgumentException $e )
{
throw new \IPS\Api\Exception( 'UPLOAD_FIELD_IMAGES_ONLY', '1T306/I', 400 );
}
}
/* Can we add a file of this type? */
if ( ( \count( $extensions ) > 0 ) AND !\in_array( '.' . $extension, $extensions ) )
{
throw new \IPS\Api\Exception( 'UPLOAD_FIELD_EXTENSION_NOT_ALLOWED', '1T306/J', 400 );
}
}
$urls = array();
foreach ( $files as $name )
{
$file = \IPS\File::create( 'cms_Records', $name, $_POST[ 'fields' ][ $field->id ][ $name ] );
$urls[] = (string) $file;
/* Do we have to create a thumbnail? */
if ( $imageOnly AND isset( $field->extra['thumbsize'] ) AND \is_array( $field->extra['thumbsize'] ) AND ( (int) $field->extra['thumbsize'][0] OR (int) $field->extra['thumbsize'][1] ) )
{
$thumbImages[$name] = array( $file, $field );
}
}
$value = implode( ',', $urls );
}
$item->$key = $value;
}
@@ -435,9 +538,29 @@ class _records extends \IPS\Content\Api\ItemController
{
$item->record_dynamic_furl = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->fields['fields'][ $item->database()->field_title ] );
}
$item = parent::_createOrUpdate( $item, $type );
$item->save();
/* Upload fields specified with images needing a thumbnail? */
foreach ( $thumbImages as $name => $imageData )
{
$file = $imageData[0];
$field = $imageData[1];
$thumbWidth = ( isset( $field->extra['thumbsize'][0] ) ) ? (int) $field->extra[ 'thumbsize' ][0] : NULL;
$thumbHeight = ( isset( $field->extra['thumbsize'][1] ) ) ? (int) $field->extra[ 'thumbsize' ][1] : NULL;
$thumbnail = $file->thumbnail( 'cms_Records', $thumbWidth ?: NULL, $thumbHeight ?: NULL );
\IPS\Db::i()->insert( 'cms_database_fields_thumbnails', array(
'thumb_original_location' => (string) $file,
'thumb_location' => (string) $thumbnail,
'thumb_field_id' => $field->id,
'thumb_database_id' => $field->database_id,
'thumb_record_id' => $item->primary_id_field,
) );
}
/* Pass up */
return parent::_createOrUpdate( $item, $type );
return $item;
}
/**
@@ -574,4 +697,135 @@ class _records extends \IPS\Content\Api\ItemController
$record->delete();
return new \IPS\Api\Response( 200, NULL );
}
}
/**
* DELETE /cms/records/{database_id}/{record_id}/react
* Deletes a reaction
*
* @param int $database Database ID Number
* @param int $record Record ID Number
* @apiparam int id ID of the reaction to add
* @apiparam int author ID of the member reacting
* @return \IPS\cms\Records
* @throws 1T306/K INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @throws 1T306/L NO_REACTION The reaction ID does not exist
* @throws 1T306/M REACT_ERROR Error adding the reaction
* @throws 1T306/N 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( $database, $record ): \IPS\Api\Response
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '1T306/K', 404 );
}
try
{
$member = \IPS\Member::load( \IPS\Request::i()->author );
}
catch( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1T306/L', 404 );
}
try
{
$class = $this->class;
$object = $class::load( $id );
$object->removeReaction( $member );
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
}
catch ( \DomainException $e )
{
throw new \IPS\Api\Exception( $e->getMessage(), '1T306/M', 403 );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1T306/N', 404 );
}
}
/**
* POST /cms/records/{database_id}/{record_id}/react
* Add a reaction
*
* @param int $database Database ID Number
* @param int $record Record ID Number
* @apiparam int id ID of the reaction to add
* @apiparam int author ID of the member reacting
* @return \IPS\cms\Records
* @throws 1T306/O INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @throws 1T306/P NO_REACTION The reaction ID does not exist
* @throws 1T306/Q NO_AUTHOR The author ID does not exist
* @throws 1T306/R REACT_ERROR Error adding the reaction
* @throws 1T306/S 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( $database, $record ): \IPS\Api\Response
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '1T306/O', 404 );
}
try
{
$reaction = \IPS\Content\Reaction::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_REACTION', '1T306/P', 404 );
}
try
{
$member = \IPS\Member::load( \IPS\Request::i()->author );
}
catch( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1T306/Q', 404 );
}
try
{
$class = $this->class;
$object = $class::load( $record );
$object->react( $reaction, $member );
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
}
catch ( \DomainException $e )
{
throw new \IPS\Api\Exception( 'REACT_ERROR_' . $e->getMessage(), '1T306/R', 403 );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1T306/S', 404 );
}
}
}
+119 -7
View File
@@ -67,7 +67,7 @@ class _reviews extends \IPS\Content\Api\CommentController
/**
* GET /cms/reviews/{database_id}
* Get list of comments
* Get list of review
*
* @note For requests using an OAuth Access Token for a particular member, only reviews the authorized user can view will be included
* @param int $database Database ID
@@ -106,7 +106,7 @@ class _reviews extends \IPS\Content\Api\CommentController
/**
* GET /cms/reviews/{database_id}/{id}
* View information about a specific comment
* View information about a specific review
*
* @param int $database Database ID
* @param int $review Comment ID
@@ -153,7 +153,7 @@ class _reviews extends \IPS\Content\Api\CommentController
/**
* POST /cms/reviews/{database_id}
* Create a comment
* Create a review
*
* @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 authenticated user has permission to hide content).
* @param int $database Database ID
@@ -164,6 +164,7 @@ class _reviews extends \IPS\Content\Api\CommentController
* @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)
* @apiparam bool anonymous If 1, the item will be posted anonymously.
* @reqapiparam int rating Star rating
* @throws 2T312/4 INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @throws 2T312/5 INVALID_ID The comment ID does not exist
@@ -222,8 +223,15 @@ class _reviews 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', '1T312/6', 400 );
}
}
}
@@ -245,7 +253,7 @@ class _reviews extends \IPS\Content\Api\CommentController
/**
* POST /cms/reviews/{database_id}/{review_id}
* Edit a comment
* Edit a review
*
* @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 authenticated user has permission to hide content).
* @param int $database Database ID
@@ -255,6 +263,7 @@ class _reviews extends \IPS\Content\Api\CommentController
* @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
* @apiparam int rating Star rating
* @apiparam bool anonymous If 1, the item will be posted anonymously.
* @throws 2T312/9 INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @throws 2T312/A INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
* @throws 1T312/B NO_AUTHOR The author ID does not exist
@@ -311,7 +320,7 @@ class _reviews extends \IPS\Content\Api\CommentController
/**
* DELETE /cms/reviews/{database_id}/{review_id}
* Deletes a comment
* Deletes a review
*
* @param int $database Database ID
* @param int $review Comment ID
@@ -355,4 +364,107 @@ class _reviews extends \IPS\Content\Api\CommentController
throw new \IPS\Api\Exception( 'INVALID_ID', '2T312/D', 404 );
}
}
/**
* POST /cms/reviews/{database_id}/{comment_id}/react
* Add a reaction
*
* @param int $database Database ID
* @param int $comment Comment ID
* @apiparam int id ID of the reaction to add
* @apiparam int author ID of the member reacting
* @return \IPS\cms\Records\Review
* @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
* @throws 2T312/E INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @note If the author has already reacted to this content, any existing reaction will be removed first
*/
public function POSTitem_react( $database, $comment )
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records\Comment' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '2T312/E', 404 );
}
return $this->_reactAdd( $comment );
}
/**
* DELETE /cms/reviews/{database_id}/{comment_id}/react
* Delete a reaction
*
* @param int $database Database ID
* @param int $comment Comment ID
* @apiparam int author ID of the member who reacted
* @return \IPS\cms\Records\Review
* @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
* @throws 2T312/F INVALID_DATABASE The database ID does not exist or the authorized user does not have permission to view it
* @note If the author has already reacted to this content, any existing reaction will be removed first
*/
public function DELETEitem_react( $database, $comment )
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records\Comment' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '2T312/F', 404 );
}
return $this->_reactRemove( $comment );
}
/**
* POST /cms/reviews/{database_id}/{comment_id}/report
* Reports a post
*
* @param int $database Database ID
* @param int $comment Comment ID
* @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\cms\Records\Review
* @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( $database, $comment )
{
/* Load database */
try
{
$database = \IPS\cms\Databases::load( $database );
if ( $this->member and !$database->can( 'view', $this->member ) )
{
throw new \OutOfRangeException;
}
$this->class = 'IPS\cms\Records\Comment' . $database->id;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_DATABASE', '2T311/D', 404 );
}
return $this->_report( $comment );
}
}