Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+9 -9
View File
@@ -10,20 +10,21 @@
*/
namespace IPS\blog\api\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\Types;
use IPS\blog\api\GraphQL\Mutations\CreateEntry;
use IPS\blog\api\GraphQL\Mutations\ReplyEntry;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Blog mutationss GraphQL API
*/
abstract class _Mutation
abstract class Mutation
{
/**
* Get the supported query types in this app
@@ -32,10 +33,9 @@ abstract class _Mutation
*/
public static function mutations(): array
{
$return = [
'createEntry' => new \IPS\blog\api\GraphQL\Mutations\CreateEntry(),
'replyEntry' => new \IPS\blog\api\GraphQL\Mutations\ReplyEntry(),
return [
'createEntry' => new CreateEntry(),
'replyEntry' => new ReplyEntry(),
];
return $return;
}
}
@@ -10,30 +10,37 @@
*/
namespace IPS\blog\api\GraphQL\Mutations;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\EntryType;
use IPS\blog\Blog;
use IPS\blog\Entry;
use IPS\Content\Api\GraphQL\ItemMutator;
use IPS\Member;
use OutOfRangeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Create blog entry mutation for GraphQL API
*/
class _CreateEntry extends \IPS\Content\Api\GraphQL\ItemMutator
class CreateEntry extends ItemMutator
{
/**
* Class
*/
protected $class = \IPS\blog\Entry::class;
protected string $class = Entry::class;
/*
* @brief Query description
*/
public static $description = "Create a new blog entry";
public static string $description = "Create a new blog entry";
/*
* Mutation arguments
@@ -48,7 +55,7 @@ class _CreateEntry extends \IPS\Content\Api\GraphQL\ItemMutator
/**
* Return the mutation return type
*/
public function type()
public function type(): EntryType
{
return \IPS\blog\api\GraphQL\TypeRegistry::entry();
}
@@ -56,37 +63,38 @@ class _CreateEntry extends \IPS\Content\Api\GraphQL\ItemMutator
/**
* Resolves this mutation
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Blog
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param mixed $info
* @return Entry
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, mixed $info): Entry
{
/* Get blog */
try
{
$blog = \IPS\blog\Blog::loadAndCheckPerms( $args['blogID'] );
$blog = Blog::loadAndCheckPerms( $args['blogID'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_BLOG', '1B300/1_graphql', 400 );
throw new SafeException( 'NO_BLOG', '1B300/1_graphql', 400 );
}
/* Check permission */
if ( !$blog->can( 'add', \IPS\Member::loggedIn() ) )
if ( !$blog->can( 'add', Member::loggedIn() ) )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '1B300/A_graphql', 403 );
throw new SafeException( 'NO_PERMISSION', '1B300/A_graphql', 403 );
}
/* Check we have a title and a post */
if ( !$args['title'] )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_TITLE', '1B300/4_graphql', 400 );
throw new SafeException( 'NO_TITLE', '1B300/4_graphql', 400 );
}
if ( !$args['content'] )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1B300/5_grapqhl', 400 );
throw new SafeException( 'NO_POST', '1B300/5_grapqhl', 400 );
}
@@ -10,30 +10,37 @@
*/
namespace IPS\blog\api\GraphQL\Mutations;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\CommentType;
use IPS\blog\Entry;
use IPS\blog\Entry\Comment;
use IPS\Content\Api\GraphQL\CommentMutator;
use IPS\Member;
use OutOfRangeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Reply to entry mutation for GraphQL API
*/
class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
class ReplyEntry extends CommentMutator
{
/**
* Class
*/
protected $class = \IPS\blog\Entry\Comment::class;
protected string $class = Comment::class;
/*
* @brief Query description
*/
public static $description = "Create a new comment";
public static string $description = "Create a new comment";
/*
* Mutation arguments
@@ -51,7 +58,7 @@ class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
/**
* Return the mutation return type
*/
public function type()
public function type(): CommentType
{
return \IPS\blog\api\GraphQL\TypeRegistry::comment();
}
@@ -59,33 +66,34 @@ class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
/**
* Resolves this mutation
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Entry
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return Comment
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, array $info): Comment
{
/* Get topic */
try
{
$entry = \IPS\blog\Entry::loadAndCheckPerms( $args['entryID'] );
$entry = Entry::loadAndCheckPerms( $args['entryID'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '1F295/1_graphql', 403 );
throw new SafeException( 'NO_TOPIC', '1F295/1_graphql', 403 );
}
/* Get author */
if ( !$entry->canComment( \IPS\Member::loggedIn() ) )
if ( !$entry->canComment( Member::loggedIn() ) )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2F294/A_graphql', 403 );
throw new SafeException( 'NO_PERMISSION', '2F294/A_graphql', 403 );
}
/* Check we have a post */
if ( !$args['content'] )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/3_graphql', 403 );
throw new SafeException( 'NO_POST', '1F295/3_graphql', 403 );
}
$originalPost = NULL;
@@ -94,9 +102,9 @@ class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
{
try
{
$originalPost = \IPS\blog\Entry\Comment::loadAndCheckPerms( $args['replyingTo'] );
$originalPost = Comment::loadAndCheckPerms( $args['replyingTo'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
// Just ignore it
}
+18 -13
View File
@@ -10,25 +10,29 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\BlogType;
use IPS\blog\Blog as BlogObject;
use OutOfRangeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Blog query for GraphQL API
*/
class _Blog
class Blog
{
/*
* @brief Query description
*/
public static $description = "Returns a Blog";
public static string $description = "Returns a Blog";
/*
* Query arguments
@@ -43,7 +47,7 @@ class _Blog
/**
* Return the query return type
*/
public function type()
public function type(): BlogType
{
return \IPS\blog\api\GraphQL\TypeRegistry::blog();
}
@@ -51,18 +55,19 @@ class _Blog
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Blog
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return BlogObject
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, array $info): BlogObject
{
$blog = \IPS\blog\Blog::load( $args['id'] );
$blog = BlogObject::load( $args[ 'id'] );
if( !$blog->can( 'view', $context['member'] ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
return $blog;
}
+15 -12
View File
@@ -10,25 +10,27 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ListOfType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\Blog;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Blogs query for GraphQL API
*/
class _Blogs
class Blogs
{
/*
* @brief Query description
*/
public static $description = "Returns a list of blogs";
public static string $description = "Returns a list of blogs";
/*
* Query arguments
@@ -43,7 +45,7 @@ class _Blogs
/**
* Return the query return type
*/
public function type()
public function type(): ListOfType
{
return TypeRegistry::listOf( \IPS\blog\api\GraphQL\TypeRegistry::blog() );
}
@@ -51,14 +53,15 @@ class _Blogs
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return array
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, array $info): array
{
\IPS\blog\Blog::loadIntoMemory('view', $context['member']);
return \IPS\blog\Blog::roots();
Blog::loadIntoMemory('view', $context['member']);
return Blog::roots();
}
}
@@ -10,25 +10,35 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use Exception;
use GraphQL\Type\Definition\ListOfType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\EntryType;
use IPS\blog\Blog;
use IPS\blog\Entry;
use IPS\Db;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use function count;
use function defined;
use function is_array;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Topics query for GraphQL API
*/
class _Entries
class Entries
{
/*
* @brief Query description
*/
public static $description = "Returns a list of blog entries";
public static string $description = "Returns a list of blog entries";
/*
* Query arguments
@@ -49,7 +59,7 @@ class _Entries
'type' => TypeRegistry::eNum([
'name' => 'blog_order_by',
'description' => 'Fields on which event can be sorted',
'values' => \IPS\blog\api\GraphQL\Types\EntryType::getOrderByOptions()
'values' => EntryType::getOrderByOptions()
]),
'defaultValue' => NULL // will use default sort option
],
@@ -71,7 +81,7 @@ class _Entries
/**
* Return the query return type
*/
public function type()
public function type(): ListOfType
{
return TypeRegistry::listOf( \IPS\blog\api\GraphQL\TypeRegistry::entry() );
}
@@ -79,29 +89,30 @@ class _Entries
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Entry
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return ActiveRecordIterator
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, array $info): ActiveRecordIterator
{
\IPS\blog\Blog::loadIntoMemory('view', \IPS\Member::loggedIn() );
Blog::loadIntoMemory('view', Member::loggedIn() );
$blogIds = [];
/* Are we filtering by blogs? */
if( isset( $args['blogs'] ) && \count( $args['blogs'] ) )
if( isset( $args['blogs'] ) && count( $args['blogs'] ) )
{
foreach( $args['blogs'] as $id )
{
$blog = \IPS\blog\Blog::loadAndCheckPerms( $id );
$blog = Blog::loadAndCheckPerms( $id );
$blogIds[] = $blog->id;
}
if( \count( $blogIds ) )
if( count( $blogIds ) )
{
$where['container'][] = array( \IPS\Db::i()->in( 'blog_blogs.blog_id', array_filter( $blogIds ) ) );
$where['container'][] = array( Db::i()->in( 'blog_blogs.blog_id', array_filter( $blogIds ) ) );
}
}
@@ -114,30 +125,30 @@ class _Entries
}
else
{
$orderBy = \IPS\blog\Entry::$databaseColumnMap[ $args['orderBy'] ];
$orderBy = Entry::$databaseColumnMap[ $args['orderBy'] ];
}
if( $args['orderBy'] === 'last_comment' )
{
$orderBy = \is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
$orderBy = is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
}
}
catch (\Exception $e)
catch (Exception)
{
$orderBy = 'last_post';
}
$sortBy = \IPS\blog\Entry::$databaseTable . '.' . \IPS\blog\Entry::$databasePrefix . "{$orderBy} {$args['orderDir']}";
$sortBy = Entry::$databaseTable . '.' . Entry::$databasePrefix . "{$orderBy} {$args['orderDir']}";
$offset = max( $args['offset'], 0 );
$limit = min( $args['limit'], 50 );
/* Figure out pinned status */
if ( $args['honorPinned'] )
{
$column = \IPS\blog\Entry::$databaseTable . '.' . \IPS\blog\Entry::$databasePrefix . \IPS\blog\Entry::$databaseColumnMap['pinned'];
$column = Entry::$databaseTable . '.' . Entry::$databasePrefix . Entry::$databaseColumnMap['pinned'];
$sortBy = "{$column} DESC, {$sortBy}";
}
return \IPS\blog\Entry::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ), 'read' );
return Entry::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ) );
}
}
+22 -17
View File
@@ -10,25 +10,29 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\EntryType;
use IPS\blog\Entry as EntryClass;
use OutOfRangeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Entry query for GraphQL API
*/
class _Entry
class Entry
{
/*
* @brief Query description
*/
public static $description = "Returns a Blog Entry";
public static string $description = "Returns a Blog Entry";
/*
* Query arguments
@@ -43,7 +47,7 @@ class _Entry
/**
* Return the query return type
*/
public function type()
public function type(): EntryType
{
return \IPS\blog\api\GraphQL\TypeRegistry::entry();
}
@@ -51,25 +55,26 @@ class _Entry
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Entry
*/
public function resolve($val, $args, $context, $info)
{
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return EntryClass
*/
public function resolve( mixed $val, array $args, array $context, array $info): EntryClass
{
try
{
$entry = \IPS\blog\Entry::loadAndCheckPerms( $args['id'] );
$entry = EntryClass::loadAndCheckPerms( $args['id'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '2B300/A_graphql', 400 );
throw new SafeException( 'NO_TOPIC', '2B300/A_graphql', 400 );
}
if( !$entry->can('read') )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2B300/9_graphql', 403 );
throw new SafeException( 'NO_PERMISSION', '2B300/9_graphql', 403 );
}
return $entry;
+12 -9
View File
@@ -10,20 +10,23 @@
*/
namespace IPS\blog\api\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\Types;
use IPS\blog\api\GraphQL\Queries\Blog;
use IPS\blog\api\GraphQL\Queries\Blogs;
use IPS\blog\api\GraphQL\Queries\Entries;
use IPS\blog\api\GraphQL\Queries\Entry;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Blog queries for GraphQL API
*/
abstract class _Query
abstract class Query
{
/**
* Get the supported query types in this app
@@ -33,10 +36,10 @@ abstract class _Query
public static function queries(): array
{
return [
'blogs' => new \IPS\blog\api\GraphQL\Queries\Blogs(),
'blog' => new \IPS\blog\api\GraphQL\Queries\Blog(),
'entries' => new \IPS\blog\api\GraphQL\Queries\Entries(),
'entry' => new \IPS\blog\api\GraphQL\Queries\Entry(),
'blogs' => new Blogs(),
'blog' => new Blog(),
'entries' => new Entries(),
'entry' => new Entry(),
];
}
}
+19 -18
View File
@@ -10,37 +10,38 @@
*/
namespace IPS\blog\api\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\Types;
use IPS\blog\api\GraphQL\Types\_BlogType;
use IPS\blog\api\GraphQL\Types\BlogType;
use IPS\blog\api\GraphQL\Types\CommentType;
use IPS\blog\api\GraphQL\Types\EntryType;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
class _TypeRegistry
class TypeRegistry
{
/**
* The blog type instance
* @var \IPS\blog\api\GraphQL\Types\BlogType
* @var BlogType
*/
protected static $blog;
protected static BlogType $blog;
/**
* The blog entry type instance
* @var \IPS\blog\api\GraphQL\Types\EntryType
* @var EntryType
*/
protected static $entry;
protected static EntryType $entry;
/**
* The entry comment instance
* @var \IPS\blog\api\GraphQL\Types\CommentType
* @var CommentType
*/
protected static $comment;
protected static CommentType $comment;
/**
* Constructor
@@ -53,24 +54,24 @@ class _TypeRegistry
/**
* @return BlogType
*/
public static function blog(): \IPS\blog\api\GraphQL\Types\BlogType
public static function blog(): BlogType
{
return self::$blog ?: (self::$blog = new \IPS\blog\api\GraphQL\Types\BlogType());
return self::$blog ?? (self::$blog = new BlogType());
}
/**
* @return EntryType
*/
public static function entry(): \IPS\blog\api\GraphQL\Types\EntryType
public static function entry(): EntryType
{
return self::$entry ?: (self::$entry = new \IPS\blog\api\GraphQL\Types\EntryType());
return self::$entry ?? (self::$entry = new EntryType());
}
/**
* @return CommentType
*/
public static function comment(): \IPS\blog\api\GraphQL\Types\CommentType
public static function comment(): CommentType
{
return self::$comment ?: (self::$comment = new \IPS\blog\api\GraphQL\Types\CommentType());
return self::$comment??( self::$comment = new CommentType() );
}
}
@@ -11,39 +11,42 @@
namespace IPS\blog\api\GraphQL\Types;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\TypeRegistry;
use IPS\blog\Blog;
use IPS\Node\Api\GraphQL\NodeType;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* BlogType for GraphQL API
*/
class _BlogType extends \IPS\Node\Api\GraphQL\NodeType
class BlogType extends NodeType
{
/*
* @brief The item classname we use for this type
*/
protected static $nodeClass = \IPS\blog\Blog::class;
protected static string $nodeClass = Blog::class;
/*
* @brief GraphQL type name
*/
protected static $typeName = 'blog_Blog';
protected static string $typeName = 'blog_Blog';
/*
* @brief GraphQL type description
*/
protected static $typeDescription = 'A blog';
protected static string $typeDescription = 'A blog';
/*
* @brief Follow data passed in to FollowType resolver
*/
protected static $followData = array('app' => 'blog', 'area' => 'blog');
protected static array $followData = array('app' => 'blog', 'area' => 'blog');
/**
@@ -51,8 +54,8 @@ class _BlogType extends \IPS\Node\Api\GraphQL\NodeType
*
* @return ObjectType
*/
public static function getItemType()
{
return \IPS\blog\api\GraphQL\TypeRegistry::entry();
public static function getItemType(): ObjectType
{
return TypeRegistry::entry();
}
}
@@ -11,43 +11,46 @@
namespace IPS\blog\api\GraphQL\Types;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\TypeRegistry;
use IPS\blog\Entry\Comment;
use IPS\Content\Api\GraphQL\CommentType as ApiCommentType;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* PostType for GraphQL API
*/
class _CommentType extends \IPS\Content\Api\GraphQL\CommentType
class CommentType extends ApiCommentType
{
/*
* @brief The item classname we use for this type
*/
protected static $commentClass = \IPS\blog\Entry\Comment::class;
protected static string $commentClass = Comment::class;
/*
* @brief GraphQL type name
*/
protected static $typeName = 'blog_Comment';
protected static string $typeName = 'blog_Comment';
/*
* @brief GraphQL type description
*/
protected static $typeDescription = 'A blog comment';
protected static string $typeDescription = 'A blog comment';
/**
* Get the item type that goes with this item type
*
* @return ObjectType
*/
public static function getItemType()
{
return \IPS\blog\api\GraphQL\TypeRegistry::comment();
public static function getItemType(): ObjectType
{
return TypeRegistry::comment();
}
/**
@@ -55,12 +58,12 @@ class _CommentType extends \IPS\Content\Api\GraphQL\CommentType
*
* @return array
*/
public function fields()
{
public function fields(): array
{
$defaultFields = parent::fields();
$postFields = array(
'entry' => [
'type' => \IPS\blog\api\GraphQL\TypeRegistry::entry(),
'type' => TypeRegistry::entry(),
'resolve' => function ($comment) {
return $comment->item();
}
@@ -11,48 +11,50 @@
namespace IPS\blog\api\GraphQL\Types;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\_TypeRegistry;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\TypeRegistry;
use IPS\blog\Entry;
use IPS\Content\Api\GraphQL\ItemType;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Entry for GraphQL API
*/
class _EntryType extends \IPS\Content\Api\GraphQL\ItemType
class EntryType extends ItemType
{
/*
* @brief The item classname we use for this type
*/
protected static $itemClass = \IPS\blog\Entry::class;
protected static string $itemClass = Entry::class;
/*
* @brief GraphQL type name
*/
protected static $typeName = 'blog_Entry';
protected static string $typeName = 'blog_Entry';
/*
* @brief GraphQL type description
*/
protected static $typeDescription = 'A blog entry';
protected static string $typeDescription = 'A blog entry';
/*
* @brief Follow data passed in to FollowType resolver
*/
protected static $followData = array('app' => 'blogs', 'area' => 'entry');
protected static array $followData = array('app' => 'blogs', 'area' => 'entry');
/**
* Get the comment type that goes with this item type
*
* @return ObjectType
*/
protected static function getCommentType()
{
return \IPS\blog\api\GraphQL\TypeRegistry::comment();
protected static function getCommentType(): ObjectType
{
return TypeRegistry::comment();
}
}
+49 -31
View File
@@ -1,4 +1,5 @@
<?php
/**
* @brief Blog Blogs API
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
@@ -12,22 +13,35 @@
namespace IPS\blog\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\blog\Blog;
use IPS\Db;
use IPS\Node\Api\NodeController;
use IPS\Request;
use OutOfRangeException;
use function defined;
use function in_array;
use function intval;
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 Blog Blogs API
*/
class _blogs extends \IPS\Node\Api\NodeController
class blogs extends NodeController
{
/**
* Class
*/
protected $class = 'IPS\blog\Blog';
protected string $class = 'IPS\blog\Blog';
/**
* GET /blog/blogs
@@ -42,31 +56,32 @@ class _blogs extends \IPS\Node\Api\NodeController
* @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>
* @apireturn PaginatedResponse<\IPS\blog\Blog>
* @return PaginatedResponse<Blog>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = $this->_globalWhere();
/* Owners */
if ( isset( \IPS\Request::i()->owners ) and isset( \IPS\Request::i()->groups ) )
if ( isset( Request::i()->owners ) and isset( Request::i()->groups ) )
{
$where[] = array( '( ' . \IPS\Db::i()->in( 'blog_member_id', array_filter( explode( ',', \IPS\Request::i()->owners ) ) ) . ' OR ' . \IPS\Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', \IPS\Request::i()->groups ) ) ) . ' )' );
$where[] = array( '( ' . Db::i()->in( 'blog_member_id', array_filter( explode( ',', Request::i()->owners ) ) ) . ' OR ' . Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', Request::i()->groups ) ) ) . ' )' );
}
elseif ( isset( \IPS\Request::i()->owners ) )
elseif ( isset( Request::i()->owners ) )
{
$where[] = array( '( ' . \IPS\Db::i()->in( 'blog_member_id', array_filter( explode( ',', \IPS\Request::i()->owners ) ) ) . ' OR blog_groupblog_ids<>? )', '' );
$where[] = array( '( ' . Db::i()->in( 'blog_member_id', array_filter( explode( ',', Request::i()->owners ) ) ) . ' OR blog_groupblog_ids<>? )', '' );
}
elseif ( isset( \IPS\Request::i()->groups ) )
elseif ( isset( Request::i()->groups ) )
{
$where[] = array( '( blog_member_id>0 OR ' . \IPS\Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', \IPS\Request::i()->groups ) ) ) . ' )' );
$where[] = array( '( blog_member_id>0 OR ' . Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', Request::i()->groups ) ) ) . ' )' );
}
/* Pinned */
if ( isset( \IPS\Request::i()->pinned ) )
if ( isset( Request::i()->pinned ) )
{
$where[] = array( 'blog_pinned=?', \intval( \IPS\Request::i()->pinned ) );
$where[] = array( 'blog_pinned=?', intval( Request::i()->pinned ) );
}
/* Permission */
@@ -76,25 +91,25 @@ class _blogs extends \IPS\Node\Api\NodeController
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'count_entries', 'last_edate' ) ) )
if ( isset( Request::i()->sortBy ) and in_array( Request::i()->sortBy, array( 'count_entries', 'last_edate' ) ) )
{
$sortBy = 'blog_' . \IPS\Request::i()->sortBy;
$sortBy = 'blog_' . Request::i()->sortBy;
}
else
{
$sortBy = 'blog_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';
/* Return */
return new \IPS\Api\PaginatedResponse(
return new PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'blog_blogs', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
Db::i()->select( '*', 'blog_blogs', $where, "{$sortBy} {$sortDir}" ),
isset( Request::i()->page ) ? Request::i()->page : 1,
'IPS\blog\Blog',
\IPS\Db::i()->select( 'COUNT(*)', 'blog_blogs', $where )->first(),
Db::i()->select( 'COUNT(*)', 'blog_blogs', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
);
}
@@ -104,9 +119,10 @@ class _blogs extends \IPS\Node\Api\NodeController
*
* @param int $id ID Number
* @throws 2B302/1 INVALID_ID The blog ID does not exist or the authorized user does not have permission to view it
* @return \IPS\blog\Blog
* @apireturn \IPS\blog\Blog
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
return $this->_view( $id );
}
@@ -116,28 +132,30 @@ class _blogs extends \IPS\Node\Api\NodeController
* Delete a blog
*
* @param int $id ID Number
* @return void
* @apireturn void
* @return Response
* @throws 2B302/2 INVALID_ID The blog ID does not exist or the authorized user does not have permission to view it
* @throws 2B302/3 NO_PERMISSION The authorized user does not have permission to delete the blog
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
/* @var Blog $class */
$class = $this->class;
try
{
$blog = $this->member ? $class::loadAndCheckPerms( $id ) : $class::load( $id );
if ( !$blog->canDelete( $this->member ) )
if ( !$blog->canDelete() )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B302/3', 404 );
throw new Exception( 'INVALID_ID', '2B302/3', 404 );
}
$blog->delete();
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B302/2', 404 );
throw new Exception( 'INVALID_ID', '2B302/2', 404 );
}
}
}
+59 -37
View File
@@ -12,22 +12,37 @@
namespace IPS\blog\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\blog\Category;
use IPS\Db;
use IPS\Http\Url\Friendly;
use IPS\Lang;
use IPS\Node\Api\NodeController;
use IPS\Node\Model;
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 Blog Blogs API
*/
class _categories extends \IPS\Node\Api\NodeController
class categories extends NodeController
{
/**
* Class
*/
protected $class = 'IPS\blog\Category';
protected string $class = 'IPS\blog\Category';
/**
* GET /blog/categories
@@ -38,33 +53,34 @@ class _categories extends \IPS\Node\Api\NodeController
* @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>
* @apireturn PaginatedResponse<IPS\blog\Category>
* @return PaginatedResponse<Category>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = $this->_globalWhere();
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'position' ) ) )
if ( isset( Request::i()->sortBy ) and Request::i()->sortBy == 'position' )
{
$sortBy = 'category_' . \IPS\Request::i()->sortBy;
$sortBy = 'category_' . Request::i()->sortBy;
}
else
{
$sortBy = 'category_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';
/* Return */
return new \IPS\Api\PaginatedResponse(
return new PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'blog_categories', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
Db::i()->select( '*', 'blog_categories', $where, "{$sortBy} {$sortDir}" ),
isset( Request::i()->page ) ? Request::i()->page : 1,
'IPS\blog\Category',
\IPS\Db::i()->select( 'COUNT(*)', 'blog_categories', $where )->first(),
Db::i()->select( 'COUNT(*)', 'blog_categories', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
);
}
@@ -73,9 +89,10 @@ class _categories extends \IPS\Node\Api\NodeController
* Get information about a specific blog category
*
* @param int $id ID Number
* @return \IPS\blog\Blog
* @apireturn \IPS\blog\Category
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
return $this->_view( $id );
}
@@ -88,17 +105,18 @@ class _categories extends \IPS\Node\Api\NodeController
* @reqapiparam string name The category name
* @apiparam int|null parent The ID number of the parent the category should be created in. NULL for root.
* @apiparam int position The category position
* @return \IPS\blog\Category
* @apireturn \IPS\blog\Category
* @throws 1B408/1 NO_TITLE A name for the category must be supplied
* @return Response
*/
public function POSTindex()
public function POSTindex(): Response
{
if ( !\IPS\Request::i()->name )
if ( !Request::i()->name )
{
throw new \IPS\Api\Exception( 'NO_TITLE', '1B408/1', 400 );
throw new Exception( 'NO_TITLE', '1B408/1', 400 );
}
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
return new Response( 201, $this->_create()->apiOutput( $this->member ) );
}
/**
@@ -110,14 +128,16 @@ class _categories extends \IPS\Node\Api\NodeController
* @apiparam int|null parent The ID number of the parent the category should be created in. NULL for root.
* @apiparam int position The category position
* @param int $id ID Number
* @return \IPS\blog\Category
* @apireturn \IPS\blog\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 ) );
}
/**
@@ -126,11 +146,13 @@ class _categories extends \IPS\Node\Api\NodeController
*
* @apiclientonly
* @param int $id ID Number
* @return void
* @apireturn void
* @return Response
* @throws 2B408/3 INVALID_ID The blog category ID does not exist or the authorized user does not have permission to delete it
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
/* @var Category $class */
$class = $this->class;
try
@@ -138,31 +160,31 @@ class _categories extends \IPS\Node\Api\NodeController
$category = $class::load( $id );
$category->delete();
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/3', 404 );
throw new Exception( 'INVALID_ID', '2B408/3', 404 );
}
}
/**
* Create or update node
*
* @param \IPS\Node\Model $category The node
* @return \IPS\Node\Model
* @param Model $node The node
* @return Model
*/
protected function _createOrUpdate( \IPS\Node\Model $category )
protected function _createOrUpdate( Model $node ): Model
{
if ( isset( \IPS\Request::i()->name ) )
if ( isset( Request::i()->name ) )
{
\IPS\Lang::saveCustom( 'blog', "blog_category_{$category->id}", \IPS\Request::i()->name );
Lang::saveCustom( 'blog', "blog_category_{$node->id}", Request::i()->name );
$category->seo_name = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->name );
$node->seo_name = Friendly::seoTitle( Request::i()->name );
}
$category->parent = (int) \IPS\Request::i()->parent?: \IPS\blog\Category::$databaseColumnParentRootValue;
$node->parent = (int) Request::i()->parent?: Category::$databaseColumnParentRootValue;
return parent::_createOrUpdate( $category );
return parent::_createOrUpdate( $node );
}
}
+73 -50
View File
@@ -12,21 +12,34 @@
namespace IPS\blog\api;
/* To prentry PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use InvalidArgumentException;
use IPS\Api\Exception;
use IPS\Api\PaginatedResponse;
use IPS\Api\Response;
use IPS\blog\Entry;
use IPS\blog\Entry\Comment;
use IPS\Content\Api\CommentController;
use IPS\Member;
use IPS\Request;
use OutOfRangeException;
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 Blog Entry Comments API
*/
class _comments extends \IPS\Content\Api\CommentController
class comments extends CommentController
{
/**
* Class
*/
protected $class = 'IPS\blog\Entry\Comment';
protected string $class = 'IPS\blog\Entry\Comment';
/**
* GET /blog/comments
@@ -43,9 +56,10 @@ class _comments extends \IPS\Content\Api\CommentController
* @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\Comment>
* @apireturn PaginatedResponse<IPS\blog\Entry\Comment>
* @return PaginatedResponse<Comment>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = array();
@@ -55,9 +69,9 @@ class _comments extends \IPS\Content\Api\CommentController
{
$where[] = array( 'entry_status=?', 'published' );
}
elseif ( isset( \IPS\Request::i()->draft ) )
elseif ( isset( Request::i()->draft ) )
{
$where[] = array( 'entry_status=?', \IPS\Request::i()->draft ? 'draft' : 'published' );
$where[] = array( 'entry_status=?', Request::i()->draft ? 'draft' : 'published' );
}
/* Return */
@@ -70,12 +84,14 @@ class _comments extends \IPS\Content\Api\CommentController
*
* @param int $id ID Number
* @throws 2B301/1 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
* @return \IPS\blog\Entry\Comment
* @apireturn \IPS\blog\Entry\Comment
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
try
{
/* @var Comment $class */
$class = $this->class;
if ( $this->member )
{
@@ -86,11 +102,11 @@ class _comments extends \IPS\Content\Api\CommentController
$object = $class::load( $id );
}
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
return new Response( 200, $object->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B301/1', 404 );
throw new Exception( 'INVALID_ID', '2B301/1', 404 );
}
}
@@ -111,18 +127,19 @@ class _comments extends \IPS\Content\Api\CommentController
* @throws 1B301/3 NO_AUTHOR The author ID does not exist
* @throws 1B301/4 NO_CONTENT No content was supplied
* @throws 2B301/8 NO_PERMISSION The authorized user does not have permission to comment on that blog entry
* @return \IPS\blog\Entry\Comment
* @apireturn \IPS\blog\Entry\Comment
* @return Response
*/
public function POSTindex()
public function POSTindex(): Response
{
/* Get entry */
try
{
$entry = \IPS\blog\Entry::load( \IPS\Request::i()->entry );
$entry = Entry::load( Request::i()->entry );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B301/2', 403 );
throw new Exception( 'INVALID_ID', '2B301/2', 403 );
}
/* Get author */
@@ -130,38 +147,38 @@ class _comments extends \IPS\Content\Api\CommentController
{
if ( !$entry->canComment( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2B301/8', 403 );
throw new Exception( 'NO_PERMISSION', '2B301/8', 403 );
}
$author = $this->member;
}
else
{
if ( \IPS\Request::i()->author )
if ( Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
$author = Member::load( Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B301/3', 404 );
throw new Exception( 'NO_AUTHOR', '1B301/3', 404 );
}
}
else
{
if ( (int) \IPS\Request::i()->author === 0 )
if ( Request::i()->author === 0 )
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
$author = new Member;
$author->name = Request::i()->author_name;
}
else
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B301/3', 400 );
throw new Exception( 'NO_AUTHOR', '1B301/3', 400 );
}
}
}
/* Check we have a post */
if ( !\IPS\Request::i()->content )
if ( !Request::i()->content )
{
throw new \IPS\Api\Exception( 'NO_CONTENT', '1B301/4', 403 );
throw new Exception( 'NO_CONTENT', '1B301/4', 403 );
}
/* Do it */
@@ -181,21 +198,22 @@ class _comments extends \IPS\Content\Api\CommentController
* @throws 2B301/5 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
* @throws 1B301/6 NO_AUTHOR The author ID does not exist
* @throws 2B301/9 NO_PERMISSION The authorized user does not have permission to edit the comment
* @return \IPS\blog\Entry\Comment
* @apireturn \IPS\blog\Entry\Comment
* @return Response
*/
public function POSTitem( $id )
public function POSTitem( int $id ): Response
{
try
{
/* Load */
$comment = \IPS\blog\Entry\Comment::load( $id );
$comment = Comment::load( $id );
if ( $this->member and !$comment->canView( $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
if ( $this->member and !$comment->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2B301/9', 403 );
throw new Exception( 'NO_PERMISSION', '2B301/9', 403 );
}
/* Do it */
@@ -203,14 +221,14 @@ class _comments extends \IPS\Content\Api\CommentController
{
return $this->_edit( $comment );
}
catch ( \InvalidArgumentException $e )
catch ( InvalidArgumentException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B301/6', 400 );
throw new Exception( 'NO_AUTHOR', '1B301/6', 400 );
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B301/5', 404 );
throw new Exception( 'INVALID_ID', '2B301/5', 404 );
}
}
@@ -221,25 +239,27 @@ class _comments extends \IPS\Content\Api\CommentController
* @param int $id ID Number
* @throws 2B301/7 INVALID_ID The comment ID does not exist
* @throws 2B301/A NO_PERMISSION The authorized user does not have permission to delete the comment
* @return void
* @apireturn void
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
try
{
{
/* @var Comment $class */
$class = $this->class;
$object = $class::load( $id );
if ( $this->member and !$object->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2B301/A', 403 );
throw new Exception( 'NO_PERMISSION', '2B301/A', 403 );
}
$object->delete();
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B301/7', 404 );
throw new Exception( 'INVALID_ID', '2B301/7', 404 );
}
}
@@ -250,14 +270,15 @@ class _comments extends \IPS\Content\Api\CommentController
* @param int $id ID Number
* @apiparam int id ID of the reaction to add
* @apiparam int author ID of the member reacting
* @return \IPS\blog\Entry\Comment
* @apireturn \IPS\blog\Entry\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
* @note If the author has already reacted to this content, any existing reaction will be removed first
* @return Response
*/
public function POSTitem_react( $id )
public function POSTitem_react( int $id ): Response
{
return $this->_reactAdd( $id );
}
@@ -268,13 +289,14 @@ class _comments extends \IPS\Content\Api\CommentController
*
* @param int $id ID Number
* @apiparam int author ID of the member who reacted
* @return \IPS\blog\Entry\Comment
* @apireturn \IPS\blog\Entry\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
* @note If the author has already reacted to this content, any existing reaction will be removed first
* @return Response
*/
public function DELETEitem_react( $id )
public function DELETEitem_react( int $id ): Response
{
return $this->_reactRemove( $id );
}
@@ -289,9 +311,10 @@ class _comments extends \IPS\Content\Api\CommentController
* @apiparam string message Optional message
* @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
* @return \IPS\blog\Entry\Comment
* @apireturn \IPS\blog\Entry\Comment
* @return Response
*/
public function POSTitem_report( $id )
public function POSTitem_report( int $id ): Response
{
return $this->_report( $id );
}
+89 -68
View File
@@ -12,21 +12,36 @@
namespace IPS\blog\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\blog\Blog;
use IPS\blog\Entry;
use IPS\blog\Entry\Comment;
use IPS\Content\Api\ItemController;
use IPS\Content\Item;
use IPS\Member;
use IPS\Request;
use IPS\Text\Parser;
use OutOfRangeException;
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 Blog Entries API
*/
class _entries extends \IPS\Content\Api\ItemController
class entries extends ItemController
{
/**
* Class
*/
protected $class = 'IPS\blog\Entry';
protected string $class = 'IPS\blog\Entry';
/**
* GET /blog/entries
@@ -45,9 +60,10 @@ class _entries extends \IPS\Content\Api\ItemController
* @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>
* @apireturn PaginatedResponse<IPS\blog\Entry>
* @return PaginatedResponse<Entry>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = array();
@@ -57,9 +73,9 @@ class _entries extends \IPS\Content\Api\ItemController
{
$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 ) )
elseif ( isset( Request::i()->draft ) )
{
$where[] = array( 'entry_status=?', \IPS\Request::i()->draft ? 'draft' : 'published' );
$where[] = array( 'entry_status=?', Request::i()->draft ? 'draft' : 'published' );
}
/* Return */
@@ -72,17 +88,18 @@ class _entries extends \IPS\Content\Api\ItemController
*
* @param int $id ID Number
* @throws 2B300/A INVALID_ID The entry ID does not exist
* @return \IPS\blog\Entry
* @apireturn \IPS\blog\Entry
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
try
{
return $this->_view( $id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B300/A', 404 );
throw new Exception( 'INVALID_ID', '2B300/A', 404 );
}
}
@@ -94,17 +111,18 @@ class _entries extends \IPS\Content\Api\ItemController
* @apiparam int page Page number
* @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>
* @apireturn PaginatedResponse<IPS\blog\Entry\Comment>
* @return PaginatedResponse<Comment>
*/
public function GETitem_comments( $id )
public function GETitem_comments( int $id ): PaginatedResponse
{
try
{
return $this->_comments( $id, 'IPS\blog\Entry\Comment' );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B300/1', 404 );
throw new Exception( 'INVALID_ID', '2B300/1', 404 );
}
}
@@ -137,18 +155,19 @@ class _entries extends \IPS\Content\Api\ItemController
* @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
* @apireturn \IPS\blog\Entry
* @return Response
*/
public function POSTindex()
public function POSTindex(): Response
{
/* Get blog */
try
{
$blog = \IPS\blog\Blog::load( \IPS\Request::i()->blog );
$blog = Blog::load( Request::i()->blog );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_BLOG', '1B300/2', 400 );
throw new Exception( 'NO_BLOG', '1B300/2', 400 );
}
/* Get author */
@@ -156,45 +175,45 @@ class _entries extends \IPS\Content\Api\ItemController
{
if ( !$blog->can( 'add', $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '1B300/A', 403 );
throw new Exception( 'NO_PERMISSION', '1B300/A', 403 );
}
$author = $this->member;
}
else
{
if ( \IPS\Request::i()->author )
if ( Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
$author = Member::load( Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B300/3', 400 );
throw new Exception( 'NO_AUTHOR', '1B300/3', 400 );
}
}
else
{
if ( (int) \IPS\Request::i()->author === 0 )
if ( Request::i()->author === 0 )
{
$author = new \IPS\Member;
$author = new Member;
}
else
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B300/3', 400 );
throw new Exception( 'NO_AUTHOR', '1B300/3', 400 );
}
}
}
/* Check we have a title and a description */
if ( !\IPS\Request::i()->title )
if ( !Request::i()->title )
{
throw new \IPS\Api\Exception( 'NO_TITLE', '1B300/4', 400 );
throw new Exception( 'NO_TITLE', '1B300/4', 400 );
}
if ( !\IPS\Request::i()->entry )
if ( !Request::i()->entry )
{
throw new \IPS\Api\Exception( 'NO_CONTENT', '1B300/5', 400 );
throw new Exception( 'NO_CONTENT', '1B300/5', 400 );
}
/* Do it */
return new \IPS\Api\Response( 201, $this->_create( $blog, $author )->apiOutput( $this->member ) );
return new Response( 201, $this->_create( $blog, $author )->apiOutput( $this->member ) );
}
/**
@@ -224,57 +243,58 @@ class _entries extends \IPS\Content\Api\ItemController
* @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
* @apireturn \IPS\blog\Entry
* @return Response
*/
public function POSTitem( $id )
public function POSTitem( int $id ): Response
{
try
{
$entry = \IPS\blog\Entry::load( $id );
$entry = Entry::load( $id );
if ( $this->member and !$entry->can( 'read', $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
if ( $this->member and !$entry->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '1B300/B', 403 );
throw new Exception( 'NO_PERMISSION', '1B300/B', 403 );
}
/* New blog */
if ( isset( \IPS\Request::i()->blog ) and \IPS\Request::i()->blog != $entry->blog_id and ( !$this->member or $entry->canMove( $this->member ) ) )
if ( isset( Request::i()->blog ) and Request::i()->blog != $entry->blog_id and ( !$this->member or $entry->canMove( $this->member ) ) )
{
try
{
$newBlog = \IPS\blog\Blog::load( \IPS\Request::i()->blog );
$newBlog = Blog::load( Request::i()->blog );
if ( $this->member and !$newBlog->can( 'add', $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
$entry->move( $newBlog );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_BLOG', '1B300/7', 400 );
throw new Exception( 'NO_BLOG', '1B300/7', 400 );
}
}
/* New author */
if ( !$this->member and isset( \IPS\Request::i()->author ) )
if ( !$this->member and isset( Request::i()->author ) )
{
try
{
$member = \IPS\Member::load( \IPS\Request::i()->author );
$member = Member::load( Request::i()->author );
if ( !$member->member_id )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
$entry->changeAuthor( $member );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1B300/8', 400 );
throw new Exception( 'NO_AUTHOR', '1B300/8', 400 );
}
}
@@ -283,36 +303,36 @@ class _entries extends \IPS\Content\Api\ItemController
/* Save and return */
$entry->save();
return new \IPS\Api\Response( 200, $entry->apiOutput( $this->member ) );
return new Response( 200, $entry->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B300/6', 404 );
throw new Exception( 'INVALID_ID', '2B300/6', 404 );
}
}
/**
* Create or update entry
*
* @param \IPS\Content\Item $item The item
* @param Item $item The item
* @param string $type add or edit
* @return \IPS\Content\Item
* @return Item
*/
protected function _createOrUpdate( \IPS\Content\Item $item, $type='add' )
protected function _createOrUpdate( Item $item, string $type='add' ): Item
{
/* Is draft */
if ( isset( \IPS\Request::i()->draft ) )
if ( isset( Request::i()->draft ) )
{
$item->status = \IPS\Request::i()->draft ? 'draft' : 'published';
$item->status = Request::i()->draft ? 'draft' : 'published';
}
/* Content */
if ( isset( \IPS\Request::i()->entry ) )
if ( isset( Request::i()->entry ) )
{
$entryContents = \IPS\Request::i()->entry;
$entryContents = Request::i()->entry;
if ( $this->member )
{
$entryContents = \IPS\Text\Parser::parseStatic( $entryContents, TRUE, NULL, $this->member, 'blog_Entries' );
$entryContents = Parser::parseStatic( $entryContents, NULL, $this->member, 'blog_Entries' );
}
$item->content = $entryContents;
}
@@ -321,9 +341,9 @@ class _entries extends \IPS\Content\Api\ItemController
$this->_createOrUpdatePoll( $item, $type );
/* Category */
if ( isset( \IPS\Request::i()->category ) )
if ( isset( Request::i()->category ) )
{
$item->category_id = \IPS\Request::i()->category;
$item->category_id = Request::i()->category;
}
/* Pass up */
@@ -337,25 +357,26 @@ class _entries extends \IPS\Content\Api\ItemController
* @param int $id ID Number
* @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
* @apireturn void
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
try
{
$item = \IPS\blog\Entry::load( $id );
$item = Entry::load( $id );
if ( $this->member and !$item->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2B300/C', 404 );
throw new Exception( 'NO_PERMISSION', '2B300/C', 404 );
}
$item->delete();
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B300/9', 404 );
throw new Exception( 'INVALID_ID', '2B300/9', 404 );
}
}
}
+44 -26
View File
@@ -12,22 +12,35 @@
namespace IPS\blog\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\blog\Entry\Category;
use IPS\Db;
use IPS\Node\Api\NodeController;
use IPS\Request;
use OutOfRangeException;
use function defined;
use function in_array;
use function intval;
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 Blog Categories API
*/
class _entrycategories extends \IPS\Node\Api\NodeController
class entrycategories extends NodeController
{
/**
* Class
*/
protected $class = 'IPS\blog\Entry\Category';
protected string $class = 'IPS\blog\Entry\Category';
/**
* GET /blog/entrycategories
@@ -38,47 +51,49 @@ class _entrycategories extends \IPS\Node\Api\NodeController
* @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\Category>
* @apireturn PaginatedResponse<IPS\blog\Entry\Category>
* @return PaginatedResponse<Category>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = array();
/* @var Category $class */
$class = $this->class;
if ( isset( \IPS\Request::i()->ids ) )
if ( isset( Request::i()->ids ) )
{
$idField = $class::$databaseTable . '.' . $class::$databasePrefix . '.' . $class::$databaseColumnId;
$where[] = array( \IPS\Db::i()->in( $idField, array_map( 'intval', explode( ',', \IPS\Request::i()->ids ) ) ) );
$where[] = array( Db::i()->in( $idField, array_map( 'intval', explode( ',', Request::i()->ids ) ) ) );
}
/* Blog */
if ( isset( \IPS\Request::i()->blog ) )
if ( isset( Request::i()->blog ) )
{
$where[] = array( 'entry_category_blog_id=?', \intval( \IPS\Request::i()->blog ) );
$where[] = array( 'entry_category_blog_id=?', intval( Request::i()->blog ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'position' ) ) )
if ( isset( Request::i()->sortBy ) and Request::i()->sortBy == 'position' )
{
$sortBy = 'entry_category_' . \IPS\Request::i()->sortBy;
$sortBy = 'entry_category_' . Request::i()->sortBy;
}
else
{
$sortBy = 'entry_category_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';
/* Return */
return new \IPS\Api\PaginatedResponse(
return new PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'blog_entry_categories', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
Db::i()->select( '*', 'blog_entry_categories', $where, "{$sortBy} {$sortDir}" ),
isset( Request::i()->page ) ? Request::i()->page : 1,
'IPS\blog\Entry\Category',
\IPS\Db::i()->select( 'COUNT(*)', 'blog_entry_categories', $where )->first(),
Db::i()->select( 'COUNT(*)', 'blog_entry_categories', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
);
}
@@ -87,9 +102,10 @@ class _entrycategories extends \IPS\Node\Api\NodeController
* Get information about a specific entry category
*
* @param int $id ID Number
* @return \IPS\blog\Entry\Category
* @apireturn \IPS\blog\Entry\Category
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
return $this->_view( $id );
}
@@ -99,11 +115,13 @@ class _entrycategories extends \IPS\Node\Api\NodeController
* Delete an entry category
*
* @param int $id ID Number
* @return void
* @apireturn void
* @throws 2B408/5 INVALID_ID The category ID does not exist or the authorized user does not have permission to delete it
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
/* @var Category $class */
$class = $this->class;
try
@@ -111,15 +129,15 @@ class _entrycategories extends \IPS\Node\Api\NodeController
$category = $class::load( $id );
if ( !$category->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/5', 404 );
throw new Exception( 'INVALID_ID', '2B408/5', 404 );
}
$category->delete();
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/6', 404 );
throw new Exception( 'INVALID_ID', '2B408/6', 404 );
}
}