Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,16 +12,29 @@
|
||||
namespace IPS\gallery\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Api\Controller;
|
||||
use IPS\Api\Exception;
|
||||
use IPS\Api\PaginatedResponse;
|
||||
use IPS\Api\Response;
|
||||
use IPS\Db;
|
||||
use IPS\gallery\Album;
|
||||
use IPS\gallery\Album\Item;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gallery Albums API
|
||||
*/
|
||||
class _albums extends \IPS\Api\Controller
|
||||
class albums extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /gallery/albums
|
||||
@@ -34,75 +47,76 @@ class _albums extends \IPS\Api\Controller
|
||||
* @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\gallery\Album>
|
||||
* @apireturn PaginatedResponse<IPS\gallery\Album>
|
||||
* @return PaginatedResponse<Album>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
|
||||
/* Categories */
|
||||
if ( isset( \IPS\Request::i()->categories ) )
|
||||
if ( isset( Request::i()->categories ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'album_category_id', array_filter( explode( ',', \IPS\Request::i()->categories ) ) ) );
|
||||
$where[] = array( Db::i()->in( 'album_category_id', array_filter( explode( ',', Request::i()->categories ) ) ) );
|
||||
}
|
||||
|
||||
/* Owners */
|
||||
if ( isset( \IPS\Request::i()->owners ) )
|
||||
if ( isset( Request::i()->owners ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'album_owner_id', array_filter( explode( ',', \IPS\Request::i()->owners ) ) ) );
|
||||
$where[] = array( Db::i()->in( 'album_owner_id', array_filter( explode( ',', Request::i()->owners ) ) ) );
|
||||
}
|
||||
|
||||
/* Privacy */
|
||||
if ( isset( \IPS\Request::i()->privacy ) )
|
||||
if ( isset( Request::i()->privacy ) )
|
||||
{
|
||||
$privacy = array();
|
||||
foreach ( array_filter( explode( ',', \IPS\Request::i()->privacy ) ) as $type )
|
||||
foreach ( array_filter( explode( ',', Request::i()->privacy ) ) as $type )
|
||||
{
|
||||
switch ( $type )
|
||||
{
|
||||
case 'public':
|
||||
$privacy[] = \IPS\gallery\Album::AUTH_TYPE_PUBLIC;
|
||||
$privacy[] = Album::AUTH_TYPE_PUBLIC;
|
||||
break;
|
||||
case 'private':
|
||||
$privacy[] = \IPS\gallery\Album::AUTH_TYPE_PRIVATE;
|
||||
$privacy[] = Album::AUTH_TYPE_PRIVATE;
|
||||
break;
|
||||
case 'restricted':
|
||||
$privacy[] = \IPS\gallery\Album::AUTH_TYPE_RESTRICTED;
|
||||
$privacy[] = Album::AUTH_TYPE_RESTRICTED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$where[] = array( \IPS\Db::i()->in( 'album_type', $privacy ) );
|
||||
$where[] = array( Db::i()->in( 'album_type', $privacy ) );
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'name', 'count_images' ) ) )
|
||||
if ( isset( Request::i()->sortBy ) and in_array( Request::i()->sortBy, array( 'name', 'count_images' ) ) )
|
||||
{
|
||||
$sortBy = 'album_' . \IPS\Request::i()->sortBy;
|
||||
$sortBy = 'album_' . 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';
|
||||
$sortDir = ( isset( Request::i()->sortDir ) and in_array( mb_strtolower( Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? Request::i()->sortDir : 'asc';
|
||||
|
||||
/* Get results */
|
||||
if ( $this->member )
|
||||
{
|
||||
$joins = array();
|
||||
$where[] = \IPS\gallery\Album\Item::getItemsWithPermissionWhere( $where, $this->member, $joins );
|
||||
$where[] = Item::getItemsWithPermissionWhere( $where, $this->member, $joins );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return new \IPS\Api\PaginatedResponse(
|
||||
return new PaginatedResponse(
|
||||
200,
|
||||
\IPS\Db::i()->select( '*', 'gallery_albums', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
Db::i()->select( '*', 'gallery_albums', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( Request::i()->page ) ? Request::i()->page : 1,
|
||||
'IPS\gallery\Album',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'gallery_albums', $where )->first(),
|
||||
Db::i()->select( 'COUNT(*)', 'gallery_albums', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -112,18 +126,19 @@ class _albums extends \IPS\Api\Controller
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2G315/1 INVALID_ID The album ID does not exist or the authorized user does not have permisison to view it
|
||||
* @return \IPS\gallery\Album
|
||||
* @apireturn \IPS\gallery\Album
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$album = $this->member ? \IPS\gallery\Album::loadAndCheckPerms( $id, 'view', $this->member ) : \IPS\gallery\Album::load( $id );
|
||||
return new \IPS\Api\Response( 200, $album->apiOutput( $this->member ) );
|
||||
$album = $this->member ? Album::loadAndCheckPerms( $id, 'view', $this->member ) : Album::load( $id );
|
||||
return new Response( 200, $album->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2G315/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2G315/1', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user