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,21 +12,33 @@
|
||||
namespace IPS\downloads\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Api\Exception;
|
||||
use IPS\Api\PaginatedResponse;
|
||||
use IPS\Api\Response;
|
||||
use IPS\downloads\Category;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Lang;
|
||||
use IPS\Node\Api\NodeController;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
use function defined;
|
||||
|
||||
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 Downloads Category API
|
||||
*/
|
||||
class _categories extends \IPS\Node\Api\NodeController
|
||||
class categories extends NodeController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\downloads\Category';
|
||||
protected string $class = 'IPS\downloads\Category';
|
||||
|
||||
/**
|
||||
* GET /downloads/categories
|
||||
@@ -36,9 +48,10 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @note For requests using an OAuth Access Token for a particular member, only categories the authorized user can view will be included
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\downloads\Category>
|
||||
* @apireturn PaginatedResponse<IPS\downloads\Category>
|
||||
* @return PaginatedResponse<Category>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Return */
|
||||
return $this->_list();
|
||||
@@ -49,9 +62,10 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* Get specific category
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\downloads\Category>
|
||||
* @apireturn IPS\downloads\Category
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
/* Return */
|
||||
return $this->_view( $id );
|
||||
@@ -72,17 +86,18 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int reviews_mod Reviews must be approved?
|
||||
* @apiparam int reviews_download Files must be downloaded before a review can be left?
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, download, reply, review) and values as permissions to use (which may be * to grant access to all groups, or an array of group IDs to permit access to)
|
||||
* @return \IPS\downloads\Category
|
||||
* @apireturn \IPS\downloads\Category
|
||||
* @throws 1D365/2 NO_TITLE A title for the category must be supplied
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTindex()
|
||||
public function POSTindex(): Response
|
||||
{
|
||||
if ( !\IPS\Request::i()->title )
|
||||
if ( !Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '1D365/2', 400 );
|
||||
throw new Exception( 'NO_TITLE', '1D365/2', 400 );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
return new Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,14 +116,16 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int reviews_download Files must be downloaded before a review can be left?
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, download, reply, review) and values as permissions to use (which may be * to grant access to all groups, or an array of group IDs to permit access to)
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\downloads\Category
|
||||
* @apireturn \IPS\downloads\Category
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
/* @var Category $class */
|
||||
$class = $this->class;
|
||||
$category = $class::load( $id );
|
||||
|
||||
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $category )->apiOutput( $this->member ) );
|
||||
return new Response( 200, $this->_createOrUpdate( $category )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,44 +134,45 @@ class _categories extends \IPS\Node\Api\NodeController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int deleteChildrenOrMove The ID number of the new parent or -1 to delete all child nodes.
|
||||
* @return void
|
||||
* @apireturn void
|
||||
* @throws 1S359/1 INVALID_ID The node ID does not exist
|
||||
* @throws 1S359/2 INVALID_TARGET The target node cannot be deleted because the new parent node does not exist
|
||||
* @throws 1S359/3 HAS_CHILDREN The target node cannot be deleted because it has children (pass deleteChildrenOrMove in the request to specify how to handle the children)
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
public function DELETEitem( int $id ): Response
|
||||
{
|
||||
return $this->_delete( $id, \IPS\Request::i()->deleteChildrenOrMove ?? NULL );
|
||||
return $this->_delete( $id, Request::i()->deleteChildrenOrMove ?? NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update node
|
||||
*
|
||||
* @param \IPS\node\Model $category The node
|
||||
* @return \IPS\node\Model
|
||||
* @param Model $category The node
|
||||
* @return Model
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\Node\Model $category )
|
||||
protected function _createOrUpdate( Model $category ): Model
|
||||
{
|
||||
foreach ( array( 'title' => "downloads_category_{$category->id}", 'description' => "downloads_category_{$category->id}_desc" ) as $fieldKey => $langKey )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$fieldKey ) )
|
||||
if ( isset( Request::i()->$fieldKey ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'downloads', $langKey, \IPS\Request::i()->$fieldKey );
|
||||
Lang::saveCustom( 'downloads', $langKey, Request::i()->$fieldKey );
|
||||
|
||||
if ( $fieldKey === 'title' )
|
||||
{
|
||||
$category->name_furl = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->$fieldKey );
|
||||
$category->name_furl = Friendly::seoTitle( Request::i()->$fieldKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$category->parent = (int) \IPS\Request::i()->parent?: 0;
|
||||
$category->parent = (int) Request::i()->parent?: 0;
|
||||
|
||||
foreach ( array( 'moderation', 'moderation_edits', 'allowss', 'reqss', 'comments', 'comment_moderation', 'reviews', 'reviews_mod', 'reviews_download' ) as $k )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$k ) )
|
||||
if ( isset( Request::i()->$k ) )
|
||||
{
|
||||
$category->bitoptions[ $k ] = \IPS\Request::i()->$k;
|
||||
$category->bitoptions[ $k ] = Request::i()->$k;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user