Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+118
View File
@@ -0,0 +1,118 @@
<?php
/**
* @brief Gallery Albums API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Gallery
* @since 14 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Gallery Albums API
*/
class _albums extends \IPS\Api\Controller
{
/**
* GET /gallery/albums
* Get list of albums
*
* @apiparam string categories Comma-delimited list of categiry IDs - if provided, only albums in those categories are returned
* @apiparam string owners Comma-delimited list of member IDs - if provided, only albums owned by those members are returned
* @apiparam string sortBy What to sort by. Can be 'name', 'count_images' for number of images, or do not specify for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Album>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Categories */
if ( isset( \IPS\Request::i()->categories ) )
{
$where[] = array( \IPS\Db::i()->in( 'album_category_id', array_filter( explode( ',', \IPS\Request::i()->categories ) ) ) );
}
/* Owners */
if ( isset( \IPS\Request::i()->owners ) )
{
$where[] = array( \IPS\Db::i()->in( 'album_owner_id', array_filter( explode( ',', \IPS\Request::i()->owners ) ) ) );
}
/* Privacy */
if ( isset( \IPS\Request::i()->privacy ) )
{
$privacy = array();
foreach ( array_filter( explode( ',', \IPS\Request::i()->privacy ) ) as $type )
{
switch ( $type )
{
case 'public':
$privacy[] = \IPS\gallery\Album::AUTH_TYPE_PUBLIC;
break;
case 'private':
$privacy[] = \IPS\gallery\Album::AUTH_TYPE_PRIVATE;
break;
case 'restricted':
$privacy[] = \IPS\gallery\Album::AUTH_TYPE_RESTRICTED;
break;
}
}
$where[] = array( \IPS\Db::i()->in( 'album_type', $privacy ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'name', 'count_images' ) ) )
{
$sortBy = 'album_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 'album_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'gallery_albums', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\gallery\Album',
\IPS\Db::i()->select( 'COUNT(*)', 'gallery_albums', $where )->first()
);
}
/**
* GET /gallery/albums/{id}
* Get information about a specific album
*
* @param int $id ID Number
* @throws 2G315/1 INVALID_ID The album ID does not exist
* @return \IPS\gallery\Album
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\gallery\Album::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G315/1', 404 );
}
}
}
+191
View File
@@ -0,0 +1,191 @@
<?php
/**
* @brief Gallery Comments API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Gallery
* @since 8 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Gallery Comments API
*/
class _comments extends \IPS\Content\Api\CommentController
{
/**
* Class
*/
protected $class = 'IPS\gallery\Image\Comment';
/**
* GET /gallery/comments
* Get list of comments
*
* @apiparam string categories Comma-delimited list of category IDs (will also include images in albums in those categories)
* @apiparam string albums Comma-delimited list of album 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 images 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 featured If 1, only comments from images which are featured are returned, if 0 only not featured
* @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
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Image\Comment>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Albums */
if ( isset( \IPS\Request::i()->albums ) )
{
$where[] = array( \IPS\Db::i()->in( 'image_album_id', array_filter( explode( ',', \IPS\Request::i()->albums ) ) ) );
}
return $this->_list( $where, 'categories' );
}
/**
* GET /gallery/comments/{id}
* View information about a specific comment
*
* @param int $id ID Number
* @throws 2L297/1 INVALID_ID The comment ID does not exist
* @return \IPS\gallery\Image\Comment
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\gallery\Image\Comment::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G317/1', 404 );
}
}
/**
* POST /gallery/comments
* Create a comment
*
* @reqapiparam int image The ID number of the image the comment is for
* @reqapiparam int author The ID number of the member making the comment (0 for guest)
* @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
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @throws 2G317/3 INVALID_ID The comment ID does not exist
* @throws 1G317/4 NO_AUTHOR The author ID does not exist
* @throws 1G317/5 NO_CONTENT No content was supplied
* @return \IPS\gallery\Image\Comment
*/
public function POSTindex()
{
/* Get topic */
try
{
$image = \IPS\gallery\Image::load( \IPS\Request::i()->image );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2L297/3', 403 );
}
/* Get author */
if ( \IPS\Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G317/4', 404 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
/* Check we have a post */
if ( !\IPS\Request::i()->content )
{
throw new \IPS\Api\Exception( 'NO_CONTENT', '1G317/5', 403 );
}
/* Do it */
return $this->_create( $image, $author );
}
/**
* POST /gallery/comments/{id}
* Edit a comment
*
* @param int $id ID Number
* @apiparam int author The ID number of the member making the comment (0 for guest)
* @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 int hidden 1/0 indicating if the topic should be hidden
* @throws 2G317/6 INVALID_ID The comment ID does not exist
* @throws 1G317/7 NO_AUTHOR The author ID does not exist
* @return \IPS\gallery\Image\Comment
*/
public function POSTitem( $id )
{
try
{
/* Load */
$comment = \IPS\gallery\Image\Comment::load( $id );
/* Do it */
try
{
return $this->_edit( $comment );
}
catch ( \InvalidArgumentException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G317/7', 400 );
}
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G317/6', 404 );
}
}
/**
* DELETE /gallery/comments/{id}
* Deletes a comment
*
* @param int $id ID Number
* @throws 2G317/8 INVALID_ID The comment ID does not exist
* @return void
*/
public function DELETEitem( $id )
{
try
{
\IPS\gallery\Image\Comment::load( $id )->delete();
return new \IPS\Api\Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G317/8', 404 );
}
}
}
+403
View File
@@ -0,0 +1,403 @@
<?php
/**
* @brief Gallery Images API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Gallery
* @since 8 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Gallery Images API
*/
class _images extends \IPS\Content\Api\ItemController
{
/**
* Class
*/
protected $class = 'IPS\gallery\Image';
/**
* GET /gallery/images
* Get list of images
*
* @apiparam string categories Comma-delimited list of category IDs (will also include images in albums in those categories)
* @apiparam string albums Comma-delimited list of album IDs
* @apiparam string authors Comma-delimited list of member IDs - if provided, only images started by those members are returned
* @apiparam int locked If 1, only images which are locked are returned, if 0 only unlocked
* @apiparam int hidden If 1, only images which are hidden are returned, if 0 only not hidden
* @apiparam int featured If 1, only images which are featured are returned, if 0 only not featured
* @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
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Image>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Albums */
if ( isset( \IPS\Request::i()->albums ) )
{
$where[] = array( \IPS\Db::i()->in( 'image_album_id', array_filter( explode( ',', \IPS\Request::i()->albums ) ) ) );
}
/* Return */
return $this->_list( $where, 'categories' );
}
/**
* GET /gallery/images/{id}
* View information about a specific image
*
* @param int $id ID Number
* @throws 2G316/1 INVALID_ID The image ID does not exist
* @return \IPS\gallery\Image
*/
public function GETitem( $id )
{
try
{
return $this->_view( $id );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G316/1', 404 );
}
}
/**
* POST /gallery/images
* Upload an image
*
* @reqapiparam int album The ID number of the album the image should be created in - not required if category is provided (only provide one or the other)
* @reqapiparam int category The ID number of the category the image should be created in - not required if album is provided (only provide one or the other)
* @reqapiparam int author The ID number of the member uploading the image (0 for guest)
* @reqapiparam string caption The image caption
* @reqapiparam string filename The image filename (e.g. 'image.png')
* @reqapiparam string image The base64 encoded image contents
* @apiparam string description The description as HTML (e.g. "<p>This is an image.</p>")
* @apiparam string copyright The copyright
* @apiparam string credit The credit information
* @apiparam int gpsShow If the image contains the location in it's EXIF data, 1/0 indicating if a map should be shown (defaults to 1)
* @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 image post date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the image. If not provided, will use the IP address from the API request
* @apiparam int locked 1/0 indicating if the image 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 image should be locked
* @apiparam int featured 1/0 indicating if the image should be featured
* @throws 1G316/2 NO_CATEGORY_OR_ALBUM The category or album does not exist
* @throws 1G316/3 NO_AUTHOR The author ID does not exist
* @throws 1G316/4 NO_CAPTION No caption was supplied
* @throws 1G316/5 NO_FILENAME No filename was supplied
* @throws 1G316/6 NO_IMAGE The image was invalid
* @return \IPS\gallery\Image
*/
public function POSTindex()
{
/* Get category or album */
if ( isset( \IPS\Request::i()->album ) )
{
try
{
$album = \IPS\gallery\Album::load( \IPS\Request::i()->album );
$category = $album->category();
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_CATEGORY_OR_ALBUM', '1G316/2', 400 );
}
}
else
{
try
{
$category = \IPS\gallery\Category::load( \IPS\Request::i()->category );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_CATEGORY_OR_ALBUM', '1G316/2', 400 );
}
}
/* Get author */
if ( \IPS\Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G316/3', 400 );
}
}
else
{
$author = new \IPS\Member;
}
/* Check we have a caption and a filename */
if ( !\IPS\Request::i()->caption )
{
throw new \IPS\Api\Exception( 'NO_CAPTION', '1G316/4', 400 );
}
if ( !\IPS\Request::i()->filename )
{
throw new \IPS\Api\Exception( 'NO_FILENAME', '1G316/5', 400 );
}
/* Check it's a valid image */
$imageContents = base64_decode( \IPS\Request::i()->image );
try
{
$imageObject = \IPS\Image::create( $imageContents );
}
catch ( \Exception $e )
{
throw new \IPS\Api\Exception( 'NO_IMAGE', '1G316/6', 400 );
}
/* Create the file */
$file = \IPS\File::create( 'gallery_Images', \IPS\Request::i()->filename, $imageContents );
/* Create the object */
$image = $this->_create( $category, $author );
/* Set properties */
$image->original_file_name = (string) $file;
$image->file_size = $file->filesize();
$image->file_name = $file->originalFilename;
$image->file_type = \IPS\File::getMimeType( $file->filename );
if( \IPS\Image::exifSupported() )
{
$image->metadata = $imageObject->parseExif();
if( count( $image->metadata ) )
{
$image->parseGeolocation();
$image->gps_show = isset( \IPS\Request::i()->gpsShow ) ? \IPS\Request::i()->gpsShow : 1;
}
$metadata = $image->metadata;
array_walk_recursive( $metadata, function( &$val, $key )
{
$val = utf8_encode( $val );
} );
$image->metadata = json_encode( $metadata );
}
$image->buildThumbnails( $file );
$image->save();
/* Output */
return new \IPS\Api\Response( 201, $image->apiOutput() );
}
/**
* POST /gallery/images/{id}
* Edit an image
*
* @apiparam int album The ID number of the album (only provide this or category to move image)
* @apiparam int category The ID number of the category (only provide this or category to move image)
* @apiparam int author The ID number of the member uploading the image (0 for guest)
* @apiparam string caption The image caption
* @apiparam string description The description as HTML (e.g. "<p>This is an image.</p>")
* @apiparam string copyright The copyright
* @apiparam string credit The credit information
* @apiparam int gpsShow If the image contains the location in it's EXIF data, 1/0 indicating if a map should be shown (defaults to 1)
* @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 image post date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the image. If not provided, will use the IP address from the API request
* @apiparam int locked 1/0 indicating if the image 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 image should be locked
* @apiparam int featured 1/0 indicating if the image should be featured
* @throws 2G316/7 INVALID_ID The image ID is invalid
* @throws 1G316/8 NO_CATEGORY_OR_ALBUM The category or album does not exist
* @throws 1G316/9 NO_AUTHOR The author ID does not exist
* @return \IPS\gallery\Image
*/
public function POSTitem( $id )
{
try
{
$image = \IPS\gallery\Image::load( $id );
/* New category or album */
try
{
if ( isset( \IPS\Request::i()->album ) and \IPS\Request::i()->album != $image->album_id )
{
$newAlbum = \IPS\gallery\Album::load( \IPS\Request::i()->album );
$image->move( $newAlbum );
}
elseif ( isset( \IPS\Request::i()->category ) and \IPS\Request::i()->category != $image->category_id )
{
$newCategory = \IPS\gallery\Category::load( \IPS\Request::i()->category );
$image->move( $newCategory );
}
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_CATEGORY_OR_ALBUM', '1G316/8', 400 );
}
/* New author */
if ( isset( \IPS\Request::i()->author ) )
{
try
{
$member = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$member->member_id )
{
throw new \OutOfRangeException;
}
$image->changeAuthor( $member );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G316/9', 400 );
}
}
/* Everything else */
$this->_createOrUpdate( $image );
/* Save and return */
$image->save();
return new \IPS\Api\Response( 200, $image->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G316/7', 404 );
}
}
/**
* GET /gallery/images/{id}/comments
* Get comments on an image
*
* @param int $id ID Number
* @apiparam int hidden If 1, only comments 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 2G316/A INVALID_ID The image ID does not exist
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Image\Comment>
*/
public function GETitem_comments( $id )
{
try
{
return $this->_comments( $id, 'IPS\gallery\Image\Comment' );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G316/A', 404 );
}
}
/**
* GET /gallery/images/{id}/reviews
* Get reviews on an image
*
* @param int $id ID Number
* @apiparam int hidden If 1, only comments 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 2G316/B INVALID_ID The image ID does not exist
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Image\Review>
*/
public function GETitem_reviews( $id )
{
try
{
return $this->_comments( $id, 'IPS\gallery\Image\Review' );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G316/B', 404 );
}
}
/**
* Create or update image
*
* @param \IPS\Content\Item $item The item
* @return \IPS\Content\Item
*/
protected function _createOrUpdate( \IPS\Content\Item $item )
{
/* Album */
if ( isset( \IPS\Request::i()->album ) and !$item->id )
{
$item->album_id = \IPS\Request::i()->album;
}
/* Caption */
if ( isset( \IPS\Request::i()->caption ) )
{
$item->caption = \IPS\Request::i()->caption;
}
/* Description */
if ( isset( \IPS\Request::i()->description ) )
{
$item->description = \IPS\Request::i()->description;
}
/* Copyright */
if ( isset( \IPS\Request::i()->copyright ) )
{
$item->copyright = \IPS\Request::i()->copyright;
}
/* Credit */
if ( isset( \IPS\Request::i()->credit ) )
{
$item->credit_info = \IPS\Request::i()->credit;
}
/* GPS Show */
if ( isset( \IPS\Request::i()->gpsShow ) )
{
$item->gps_show = \IPS\Request::i()->gpsShow;
}
/* Pass up */
return parent::_createOrUpdate( $item );
}
/**
* DELETE /gallery/images/{id}
* Delete an image
*
* @param int $id ID Number
* @throws 2G316/C INVALID_ID The image ID does not exist
* @return void
*/
public function DELETEitem( $id )
{
try
{
\IPS\gallery\Image::load( $id )->delete();
return new \IPS\Api\Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G316/C', 404 );
}
}
}
+206
View File
@@ -0,0 +1,206 @@
<?php
/**
* @brief Gallery Reviews API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Gallery
* @since 8 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Gallery Reviews API
*/
class _reviews extends \IPS\Content\Api\CommentController
{
/**
* Class
*/
protected $class = 'IPS\gallery\Image\Review';
/**
* GET /gallery/reviews
* Get list of reviews
*
* @apiparam string categories Comma-delimited list of category IDs (will also include images in albums in those categories)
* @apiparam string albums Comma-delimited list of album 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 reviews from images which are locked are returned, if 0 only unlocked
* @apiparam int hidden If 1, only reviews which are hidden are returned, if 0 only not hidden
* @apiparam int featured If 1, only reviews from images which are featured are returned, if 0 only not featured
* @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
* @return \IPS\Api\PaginatedResponse<IPS\gallery\Image\Review>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Albums */
if ( isset( \IPS\Request::i()->albums ) )
{
$where[] = array( \IPS\Db::i()->in( 'image_album_id', array_filter( explode( ',', \IPS\Request::i()->albums ) ) ) );
}
return $this->_list( $where, 'categories' );
}
/**
* GET /gallery/reviews/{id}
* View information about a specific review
*
* @param int $id ID Number
* @throws 2G318/1 INVALID_ID The review ID does not exist
* @return \IPS\gallery\Image\Review
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\gallery\Image\Review::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G318/1', 404 );
}
}
/**
* POST /gallery/reviews
* Create a review
*
* @reqapiparam int image The ID number of the image the review is for
* @reqapiparam int author The ID number of the member making the review (0 for guest)
* @apiparam string author_name If author is 0, the guest name that should be used
* @reqapiparam string content The review content as HTML (e.g. "<p>This is a review.</p>")
* @apiparam datetime date The date/time that should be used for the review date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the review. If not provided, will use the IP address from the API request
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @reqapiparam int rating Star rating
* @throws 2G318/8 INVALID_ID The forum ID does not exist
* @throws 1G318/3 NO_AUTHOR The author ID does not exist
* @throws 1L298/4 NO_CONTENT No content was supplied
* @throws 1G318/5 INVALID_RATING The rating is not a valid number up to the maximum rating
* @return \IPS\gallery\Image\Review
*/
public function POSTindex()
{
/* Get topic */
try
{
$image = \IPS\gallery\Image::load( \IPS\Request::i()->image );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G318/2', 403 );
}
/* Get author */
if ( \IPS\Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G318/3', 404 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
/* Check we have a post */
if ( !\IPS\Request::i()->content )
{
throw new \IPS\Api\Exception( 'NO_CONTENT', '1G318/4', 403 );
}
/* Check we have a rating */
if ( !\IPS\Request::i()->rating or !in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
{
throw new \IPS\Api\Exception( 'INVALID_RATING', '2G318/8', 403 );
}
/* Do it */
return $this->_create( $image, $author );
}
/**
* POST /gallery/reviews/{id}
* Edit a review
*
* @param int $id ID Number
* @apiparam int author The ID number of the member making the review (0 for guest)
* @apiparam string author_name If author is 0, the guest name that should be used
* @apiparam string content The review content as HTML (e.g. "<p>This is a review.</p>")
* @apiparam int hidden 1/0 indicating if the topic should be hidden
* @apiparam int rating Star rating
* @throws 2L298/5 INVALID_ID The review ID does not exist
* @throws 1G318/B NO_AUTHOR The author ID does not exist
* @throws 1G318/A INVALID_RATING The rating is not a valid number up to the maximum rating
* @return \IPS\gallery\Image\Review
*/
public function POSTitem( $id )
{
try
{
/* Load */
$comment = \IPS\gallery\Image\Review::load( $id );
/* Check */
if ( isset( \IPS\Request::i()->rating ) and !in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
{
throw new \IPS\Api\Exception( 'INVALID_RATING', '1G318/A', 403 );
}
/* Do it */
try
{
return $this->_edit( $comment );
}
catch ( \InvalidArgumentException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1G318/B', 400 );
}
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G318/9', 404 );
}
}
/**
* DELETE /gallery/reviews/{id}
* Deletes a review
*
* @param int $id ID Number
* @throws 2G318/C INVALID_ID The review ID does not exist
* @return void
*/
public function DELETEitem( $id )
{
try
{
\IPS\gallery\Image\Review::load( $id )->delete();
return new \IPS\Api\Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2G318/C', 404 );
}
}
}