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
@@ -10,41 +10,52 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\forums\api\GraphQL\Mutations\CreateTopic;
|
||||
use IPS\forums\api\GraphQL\Mutations\MarkForumRead;
|
||||
use IPS\forums\api\GraphQL\Mutations\MarkTopicRead;
|
||||
use IPS\forums\api\GraphQL\Mutations\MarkTopicSolved;
|
||||
use IPS\forums\api\GraphQL\Mutations\PostReaction;
|
||||
use IPS\forums\api\GraphQL\Mutations\ReplyTopic;
|
||||
use IPS\forums\api\GraphQL\Mutations\ReportPost;
|
||||
use IPS\forums\api\GraphQL\Mutations\RevokePostReport;
|
||||
use IPS\forums\api\GraphQL\Mutations\SetBestAnswer;
|
||||
use IPS\forums\api\GraphQL\Mutations\VoteAnswer;
|
||||
use IPS\forums\api\GraphQL\Mutations\VoteInPoll;
|
||||
use IPS\forums\api\GraphQL\Mutations\VoteQuestion;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forums mutationss GraphQL API
|
||||
*/
|
||||
abstract class _Mutation
|
||||
abstract class Mutation
|
||||
{
|
||||
/**
|
||||
* Get the supported query types in this app
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function mutations()
|
||||
public static function mutations() : array
|
||||
{
|
||||
return [
|
||||
'createTopic' => new \IPS\forums\api\GraphQL\Mutations\CreateTopic(),
|
||||
'replyTopic' => new \IPS\forums\api\GraphQL\Mutations\ReplyTopic(),
|
||||
'postReaction' => new \IPS\forums\api\GraphQL\Mutations\PostReaction(),
|
||||
'markForumRead' => new \IPS\forums\api\GraphQL\Mutations\MarkForumRead(),
|
||||
'markTopicRead' => new \IPS\forums\api\GraphQL\Mutations\MarkTopicRead(),
|
||||
'markTopicSolved' => new \IPS\forums\api\GraphQL\Mutations\MarkTopicSolved(),
|
||||
'voteInPoll' => new \IPS\forums\api\GraphQL\Mutations\VoteInPoll(),
|
||||
'voteQuestion' => new \IPS\forums\api\GraphQL\Mutations\VoteQuestion(),
|
||||
'voteAnswer' => new \IPS\forums\api\GraphQL\Mutations\VoteAnswer(),
|
||||
'setBestAnswer' => new \IPS\forums\api\GraphQL\Mutations\SetBestAnswer(),
|
||||
'reportPost' => new \IPS\forums\api\GraphQL\Mutations\ReportPost(),
|
||||
'revokePostReport' => new \IPS\forums\api\GraphQL\Mutations\RevokePostReport(),
|
||||
'createTopic' => new CreateTopic(),
|
||||
'replyTopic' => new ReplyTopic(),
|
||||
'postReaction' => new PostReaction(),
|
||||
'markForumRead' => new MarkForumRead(),
|
||||
'markTopicRead' => new MarkTopicRead(),
|
||||
'markTopicSolved' => new MarkTopicSolved(),
|
||||
'voteInPoll' => new VoteInPoll(),
|
||||
'voteQuestion' => new VoteQuestion(),
|
||||
'voteAnswer' => new VoteAnswer(),
|
||||
'setBestAnswer' => new SetBestAnswer(),
|
||||
'reportPost' => new ReportPost(),
|
||||
'revokePostReport' => new RevokePostReport(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,30 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\ItemMutator;
|
||||
use IPS\Content\Item;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
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 topic mutation for GraphQL API
|
||||
*/
|
||||
class _CreateTopic extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
class CreateTopic extends ItemMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic';
|
||||
protected string $class = 'IPS\forums\Topic';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Create a new topic";
|
||||
public static string $description = "Create a new topic";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -52,51 +60,52 @@ class _CreateTopic extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Item
|
||||
{
|
||||
/* Get forum */
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::loadAndCheckPerms( $args['forumID'] );
|
||||
$forum = Forum::loadAndCheckPerms( $args['forumID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_FORUM', '1F294/2_graphl', 400 );
|
||||
throw new SafeException( 'NO_FORUM', '1F294/2_graphl', 400 );
|
||||
}
|
||||
|
||||
/* Check permission */
|
||||
if ( !$forum->can( 'add', \IPS\Member::loggedIn() ) )
|
||||
if ( !$forum->can( 'add', Member::loggedIn() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2F294/9_graphl', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '2F294/9_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a title and a post */
|
||||
if ( !$args['title'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TITLE', '1F294/5_graphl', 400 );
|
||||
throw new SafeException( 'NO_TITLE', '1F294/5_graphl', 400 );
|
||||
}
|
||||
if ( !$args['content'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F294/4_graphl', 400 );
|
||||
throw new SafeException( 'NO_POST', '1F294/4_graphl', 400 );
|
||||
}
|
||||
|
||||
|
||||
$item = $this->_create( $args, $forum, $args['postKey'] ?? NULL );
|
||||
|
||||
return $item;
|
||||
return $this->_create( $args, $forum, $args['postKey'] ?? NULL );
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,31 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\ForumType;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Node\Api\GraphQL\NodeMutator;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark forum read mutation for GraphQL API
|
||||
*/
|
||||
class _MarkForumRead extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
class MarkForumRead extends NodeMutator
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a forum as read";
|
||||
public static string $description = "Mark a forum as read";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -42,8 +48,10 @@ class _MarkForumRead extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return ForumType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ForumType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::forum();
|
||||
}
|
||||
@@ -51,20 +59,19 @@ class _MarkForumRead extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Forum
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Forum
|
||||
{
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::loadAndCheckPerms( \intval( $args['id'] ) );
|
||||
$forum = Forum::loadAndCheckPerms( intval( $args['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_NODE', 'GQL/0004/2', 403 );
|
||||
throw new SafeException( 'INVALID_NODE', 'GQL/0004/2', 403 );
|
||||
}
|
||||
|
||||
$this->_markRead( $forum );
|
||||
|
||||
@@ -10,25 +10,30 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\ItemMutator;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark topic read mutation for GraphQL API
|
||||
*/
|
||||
class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
class MarkTopicRead extends ItemMutator
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a topic as read";
|
||||
public static string $description = "Mark a topic as read";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -42,8 +47,10 @@ class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @reutrn TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -51,25 +58,24 @@ class _MarkTopicRead 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\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['id'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', 'GQL/0005/1', 400 );
|
||||
throw new SafeException( 'NO_TOPIC', 'GQL/0005/1', 400 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0005/2', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0005/2', 403 );
|
||||
}
|
||||
|
||||
$this->_markRead( $topic );
|
||||
|
||||
@@ -10,25 +10,35 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Api\GraphQL\NodeMutator;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark topic solved mutation for GraphQL API
|
||||
*/
|
||||
class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
class MarkTopicSolved extends NodeMutator
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a topic solved";
|
||||
public static string $description = "Mark a topic solved";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -47,8 +57,10 @@ class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -56,34 +68,34 @@ class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @return \IPS\forums\Topic
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( \intval( $args['id'] ) );
|
||||
$topic = Topic::loadAndCheckPerms( intval( $args['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', 'GQL', 403 );
|
||||
throw new SafeException( 'NO_TOPIC', 'GQL', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( \intval( $args['answer'] ) );
|
||||
$post = Post::loadAndCheckPerms( intval( $args['answer'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', 'GQL', 403 );
|
||||
throw new SafeException( 'NO_POST', 'GQL', 403 );
|
||||
}
|
||||
|
||||
/* This is "solved" mode */
|
||||
if ( !$topic->canSolve() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', 'GQL', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', 'GQL', 403 );
|
||||
}
|
||||
|
||||
|
||||
@@ -96,12 +108,12 @@ class _MarkTopicSolved extends \IPS\Node\Api\GraphQL\NodeMutator
|
||||
$topic->toggleSolveComment( $post->pid, FALSE );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'core_moderator_logs', array(
|
||||
'member_id' => \IPS\Member::loggedIn()->member_id,
|
||||
'member_name' => \IPS\Member::loggedIn()->name,
|
||||
Db::i()->insert( 'core_moderator_logs', array(
|
||||
'member_id' => Member::loggedIn()->member_id,
|
||||
'member_name' => Member::loggedIn()->name,
|
||||
'ctime' => time(),
|
||||
'note' => json_encode( array( $post->pid => $args['solved'] ) ),
|
||||
'ip_address' => \IPS\Request::i()->ipAddress(),
|
||||
'ip_address' => Request::i()->ipAddress(),
|
||||
'appcomponent' => 'forums',
|
||||
'module' => 'forums',
|
||||
'controller' => 'topic',
|
||||
|
||||
@@ -10,30 +10,35 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\CommentMutator;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* React to post mutation for GraphQL API
|
||||
*/
|
||||
class _PostReaction extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class PostReaction extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "React to a post";
|
||||
public static string $description = "React to a post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -49,30 +54,33 @@ class _PostReaction extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Post
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['postID'] );
|
||||
$post = Post::loadAndCheckPerms( $args['postID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
|
||||
@@ -10,30 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\CommentMutator;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
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 topic mutation for GraphQL API
|
||||
*/
|
||||
class _ReplyTopic extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class ReplyTopic extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Create a new post";
|
||||
public static string $description = "Create a new post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -50,42 +58,45 @@ class _ReplyTopic extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Comment
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['topicID'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['topicID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_TOPIC', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
if ( !$topic->canComment( \IPS\Member::loggedIn() ) )
|
||||
if ( !$topic->canComment( Member::loggedIn() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2F294/A_graphl', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '2F294/A_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
if ( !$args['content'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/3_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/3_graphl', 403 );
|
||||
}
|
||||
|
||||
$originalPost = NULL;
|
||||
@@ -94,9 +105,9 @@ class _ReplyTopic extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
{
|
||||
try
|
||||
{
|
||||
$originalPost = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['replyingTo'] );
|
||||
$originalPost = Post::loadAndCheckPerms( $args['replyingTo'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
// Just ignore it
|
||||
}
|
||||
|
||||
@@ -10,30 +10,36 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\CommentMutator;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report post mutation for GraphQL API
|
||||
*/
|
||||
class _ReportPost extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class ReportPost extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Report a post";
|
||||
public static string $description = "Report a post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -52,30 +58,33 @@ class _ReportPost extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Comment
|
||||
{
|
||||
/* Get post */
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
|
||||
@@ -10,30 +10,36 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\CommentMutator;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke post report mutation for GraphQL API
|
||||
*/
|
||||
class _RevokePostReport extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class RevokePostReport extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Report a post";
|
||||
public static string $description = "Report a post";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -48,30 +54,33 @@ class _RevokePostReport extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : Comment
|
||||
{
|
||||
/* Get post */
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/1_graphl', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
|
||||
@@ -10,25 +10,30 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use Exception;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a post as best answer mutation for GraphQL API
|
||||
*/
|
||||
class _SetBestAnswer
|
||||
class SetBestAnswer
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Set a post as best answer";
|
||||
public static string $description = "Set a post as best answer";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -42,8 +47,10 @@ class _SetBestAnswer
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
@@ -51,36 +58,30 @@ class _SetBestAnswer
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Post
|
||||
{
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
$topic = $post->item();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', 'GQL/0010/1', 403 );
|
||||
throw new SafeException( 'NO_POST', 'GQL/0010/1', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0010/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NON_QUESTION', 'GQL/0010/3', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0010/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->canSetBestAnswer() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', 'GQL/0010/4', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', 'GQL/0010/4', 403 );
|
||||
}
|
||||
|
||||
// Do we have an existing best answer
|
||||
@@ -88,11 +89,11 @@ class _SetBestAnswer
|
||||
{
|
||||
try
|
||||
{
|
||||
$oldBestAnswer = \IPS\forums\Topic\Post::load( $topic->topic_answered_pid );
|
||||
$oldBestAnswer = Post::load( $topic->topic_answered_pid );
|
||||
$oldBestAnswer->post_bwoptions['best_answer'] = FALSE;
|
||||
$oldBestAnswer->save();
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
catch ( Exception $e ) {}
|
||||
}
|
||||
|
||||
$post->post_bwoptions['best_answer'] = TRUE;
|
||||
|
||||
@@ -10,25 +10,32 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote on an answer mutation for GraphQL API
|
||||
*/
|
||||
class _VoteAnswer
|
||||
class VoteAnswer
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Vote on an answer";
|
||||
public static string $description = "Vote on an answer";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -43,8 +50,10 @@ class _VoteAnswer
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
@@ -52,36 +61,30 @@ class _VoteAnswer
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Post
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Post
|
||||
{
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = Post::loadAndCheckPerms( $args['id'] );
|
||||
$topic = $post->item();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', 'GQL/0009/1', 403 );
|
||||
throw new SafeException( 'NO_POST', 'GQL/0009/1', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0009/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NON_QUESTION', 'GQL/0009/3', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0009/2', 403 );
|
||||
}
|
||||
|
||||
if( !$post->canVote() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANNOT_VOTE', 'GQL/0009/4', 403 );
|
||||
throw new SafeException( 'CANNOT_VOTE', 'GQL/0009/4', 403 );
|
||||
}
|
||||
|
||||
$rating = $args['vote'] == 'UP' ? 1 : -1;
|
||||
@@ -89,20 +92,19 @@ class _VoteAnswer
|
||||
/* Have we already rated ? */
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->delete( 'forums_answer_ratings', array( 'topic=? AND post=? AND `member`=?', $topic->tid, $post->pid, \IPS\Member::loggedIn()->member_id ) );
|
||||
Db::i()->delete( 'forums_answer_ratings', array( 'topic=? AND post=? AND `member`=?', $topic->tid, $post->pid, Member::loggedIn()->member_id ) );
|
||||
}
|
||||
catch ( \UnderflowException $e ){}
|
||||
catch ( UnderflowException $e ){}
|
||||
|
||||
\IPS\Db::i()->insert( 'forums_answer_ratings', array(
|
||||
Db::i()->insert( 'forums_answer_ratings', array(
|
||||
'post' => $post->pid,
|
||||
'topic' => $topic->tid,
|
||||
'member' => \IPS\Member::loggedIn()->member_id,
|
||||
'member' => Member::loggedIn()->member_id,
|
||||
'rating' => $rating,
|
||||
'date' => time()
|
||||
), TRUE );
|
||||
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition */
|
||||
$post->post_field_int = (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $post->pid ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$post->post_field_int = (int) Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $post->pid ), NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$post->save();
|
||||
|
||||
return $post;
|
||||
|
||||
@@ -10,31 +10,36 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Poll\Api\GraphQL\PollMutator;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote in poll mutation for GraphQL API
|
||||
*/
|
||||
class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
class VoteInPoll extends PollMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic';
|
||||
protected string $class = 'IPS\forums\Topic';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Vote in a poll in a topic";
|
||||
public static string $description = "Vote in a poll in a topic";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -57,8 +62,10 @@ class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -66,27 +73,26 @@ class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['itemID'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['itemID'] );
|
||||
$poll = $topic->getPoll();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_TOPIC', 'GQL/0006/1', 403 );
|
||||
throw new SafeException( 'INVALID_TOPIC', 'GQL/0006/1', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') || $poll === NULL )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POLL', 'GQL/0006/2', 403 );
|
||||
throw new SafeException( 'NO_POLL', 'GQL/0006/2', 403 );
|
||||
}
|
||||
|
||||
$this->_vote( $poll, $args['poll'] );
|
||||
|
||||
@@ -10,25 +10,31 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote on a question mutation for GraphQL API
|
||||
*/
|
||||
class _VoteQuestion
|
||||
class VoteQuestion
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Vote on a question";
|
||||
public static string $description = "Vote on a question";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -43,8 +49,10 @@ class _VoteQuestion
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -52,57 +60,50 @@ class _VoteQuestion
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['id'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', 'GQL/0008/1', 400 );
|
||||
throw new SafeException( 'NO_TOPIC', 'GQL/0008/1', 400 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0008/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NON_QUESTION', 'GQL/0008/3', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0008/2', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->canVote() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANNOT_VOTE', 'GQL/0008/4', 403 );
|
||||
throw new SafeException( 'CANNOT_VOTE', 'GQL/0008/4', 403 );
|
||||
}
|
||||
|
||||
$rating = $args['vote'] == 'UP' ? 1 : -1;
|
||||
|
||||
// If we have an existing vote, undo that
|
||||
$ratings = $topic->votes();
|
||||
if ( isset( $ratings[ \IPS\Member::loggedIn()->member_id ] ) )
|
||||
if ( isset( $ratings[ Member::loggedIn()->member_id ] ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'forums_question_ratings', array( 'topic=? AND member=?', $topic->tid, \IPS\Member::loggedIn()->member_id ) );
|
||||
Db::i()->delete( 'forums_question_ratings', array( 'topic=? AND member=?', $topic->tid, Member::loggedIn()->member_id ) );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'forums_question_ratings', array(
|
||||
Db::i()->insert( 'forums_question_ratings', array(
|
||||
'topic' => $topic->tid,
|
||||
'forum' => $topic->forum_id,
|
||||
'member' => \IPS\Member::loggedIn()->member_id,
|
||||
'member' => Member::loggedIn()->member_id,
|
||||
'rating' => $rating,
|
||||
'date' => time()
|
||||
), TRUE );
|
||||
|
||||
/* Rebuild count */
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition */
|
||||
$topic->question_rating = \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic->tid ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$topic->question_rating = Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic->tid ), NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$topic->save();
|
||||
|
||||
return $topic;
|
||||
|
||||
@@ -10,25 +10,28 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\ForumType;
|
||||
use IPS\forums\Forum as ForumClass;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forum query for GraphQL API
|
||||
*/
|
||||
class _Forum
|
||||
class Forum
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a forum";
|
||||
public static string $description = "Returns a forum";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -43,8 +46,10 @@ class _Forum
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return ForumType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ForumType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::forum();
|
||||
}
|
||||
@@ -52,18 +57,19 @@ class _Forum
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return ForumClass
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : ForumClass
|
||||
{
|
||||
$forum = \IPS\forums\Forum::load( $args['id'] );
|
||||
$forum = ForumClass::load( $args['id'] );
|
||||
|
||||
if( !$forum->can( 'view', $context['member'] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
return $forum;
|
||||
}
|
||||
|
||||
@@ -10,25 +10,28 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\ForumType;
|
||||
use IPS\forums\Forum;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forums query for GraphQL API
|
||||
*/
|
||||
class _Forums
|
||||
class Forums
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of forums";
|
||||
public static string $description = "Returns a list of forums";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -42,8 +45,10 @@ class _Forums
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return ListOfType<ForumType>
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\forums\api\GraphQL\TypeRegistry::forum() );
|
||||
}
|
||||
@@ -51,14 +56,15 @@ class _Forums
|
||||
/**
|
||||
* 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\forums\Forum::loadIntoMemory('view', $context['member']);
|
||||
return \IPS\forums\Forum::roots();
|
||||
Forum::loadIntoMemory('view', $context['member']);
|
||||
return Forum::roots();
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,28 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\Topic\Post as PostClass;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post query for GraphQL API
|
||||
*/
|
||||
class _Post
|
||||
class Post
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a post";
|
||||
public static string $description = "Returns a post";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -42,8 +45,10 @@ class _Post
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return PostType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : PostType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
@@ -51,18 +56,19 @@ class _Post
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return PostClass
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : PostClass
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( $args['id'] );
|
||||
$post = PostClass::loadAndCheckPerms( $args['id'] );
|
||||
|
||||
if( !$post->item()->canView() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
return $post;
|
||||
}
|
||||
|
||||
@@ -10,25 +10,29 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic as TopicClass;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Topic query for GraphQL API
|
||||
*/
|
||||
class _Topic
|
||||
class Topic
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a topic";
|
||||
public static string $description = "Returns a topic";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -42,8 +46,10 @@ class _Topic
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -51,25 +57,26 @@ class _Topic
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return TopicClass
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : TopicClass
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['id'] );
|
||||
$topic = TopicClass::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '1F294/2_graphql', 400 );
|
||||
throw new SafeException( 'NO_TOPIC', '1F294/2_graphql', 400 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', '2F294/9_graphql', 403 );
|
||||
throw new SafeException( 'INVALID_ID', '2F294/9_graphql', 403 );
|
||||
}
|
||||
|
||||
return $topic;
|
||||
|
||||
@@ -10,25 +10,35 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use Exception;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
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 _Topics
|
||||
class Topics
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of topics";
|
||||
public static string $description = "Returns a list of topics";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -49,7 +59,7 @@ class _Topics
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => 'forums_fluid_order_by',
|
||||
'description' => 'Fields on which topics can be sorted',
|
||||
'values' => \IPS\forums\api\GraphQL\Types\TopicType::getOrderByOptions()
|
||||
'values' => TopicType::getOrderByOptions()
|
||||
]),
|
||||
'defaultValue' => NULL // will use default sort option
|
||||
],
|
||||
@@ -70,8 +80,10 @@ class _Topics
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return ListOfType<TopicType>
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\forums\api\GraphQL\TypeRegistry::topic() );
|
||||
}
|
||||
@@ -79,30 +91,31 @@ class _Topics
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic
|
||||
* @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\forums\Forum::loadIntoMemory('view', \IPS\Member::loggedIn() );
|
||||
Forum::loadIntoMemory('view', Member::loggedIn() );
|
||||
|
||||
$where = array( 'container' => array( array( 'forums_forums.password IS NULL' ) ) );
|
||||
$forumIDs = [];
|
||||
|
||||
/* Are we filtering by forums? */
|
||||
if( isset( $args['forums'] ) && \count( $args['forums'] ) )
|
||||
if( isset( $args['forums'] ) && count( $args['forums'] ) )
|
||||
{
|
||||
foreach( $args['forums'] as $id )
|
||||
{
|
||||
$forum = \IPS\forums\Forum::loadAndCheckPerms( $id );
|
||||
$forum = Forum::loadAndCheckPerms( $id );
|
||||
$forumIDs[] = $forum->id;
|
||||
}
|
||||
|
||||
if( \count( $forumIDs ) )
|
||||
if( count( $forumIDs ) )
|
||||
{
|
||||
$where['container'][] = array( \IPS\Db::i()->in( 'forums_forums.id', array_filter( $forumIDs ) ) );
|
||||
$where['container'][] = array( Db::i()->in( 'forums_forums.id', array_filter( $forumIDs ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,30 +128,30 @@ class _Topics
|
||||
}
|
||||
else
|
||||
{
|
||||
$orderBy = \IPS\forums\Topic::$databaseColumnMap[ $args['orderBy'] ];
|
||||
$orderBy = Topic::$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 $e)
|
||||
{
|
||||
$orderBy = 'last_post';
|
||||
}
|
||||
|
||||
$sortBy = \IPS\forums\Topic::$databaseTable . '.' . \IPS\forums\Topic::$databasePrefix . "{$orderBy} {$args['orderDir']}";
|
||||
$sortBy = Topic::$databaseTable . '.' . Topic::$databasePrefix . "{$orderBy} {$args['orderDir']}";
|
||||
$offset = max( $args['offset'], 0 );
|
||||
$limit = min( $args['limit'], 50 );
|
||||
|
||||
/* Figure out pinned status */
|
||||
if ( $args['honorPinned'] )
|
||||
{
|
||||
$column = \IPS\forums\Topic::$databaseTable . '.' . \IPS\forums\Topic::$databasePrefix . \IPS\forums\Topic::$databaseColumnMap['pinned'];
|
||||
$column = Topic::$databaseTable . '.' . Topic::$databasePrefix . Topic::$databaseColumnMap['pinned'];
|
||||
$sortBy = "{$column} DESC, {$sortBy}";
|
||||
}
|
||||
|
||||
return \IPS\forums\Topic::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ), 'read' );
|
||||
return Topic::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ), 'read' );
|
||||
}
|
||||
}
|
||||
@@ -10,34 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\forums\api\GraphQL\Queries\Forum;
|
||||
use IPS\forums\api\GraphQL\Queries\Forums;
|
||||
use IPS\forums\api\GraphQL\Queries\Post;
|
||||
use IPS\forums\api\GraphQL\Queries\Topic;
|
||||
use IPS\forums\api\GraphQL\Queries\Topics;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forums queries for GraphQL API
|
||||
*/
|
||||
abstract class _Query
|
||||
abstract class Query
|
||||
{
|
||||
/**
|
||||
* Get the supported query types in this app
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function queries()
|
||||
public static function queries() : array
|
||||
{
|
||||
return [
|
||||
'forums' => new \IPS\forums\api\GraphQL\Queries\Forums(),
|
||||
'forum' => new \IPS\forums\api\GraphQL\Queries\Forum(),
|
||||
'topics' => new \IPS\forums\api\GraphQL\Queries\Topics(),
|
||||
'topic' => new \IPS\forums\api\GraphQL\Queries\Topic(),
|
||||
'post' => new \IPS\forums\api\GraphQL\Queries\Post()
|
||||
'forums' => new Forums(),
|
||||
'forum' => new Forum(),
|
||||
'topics' => new Topics(),
|
||||
'topic' => new Topic(),
|
||||
'post' => new Post()
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\forums\api\GraphQL\Types\ForumType;
|
||||
use IPS\forums\api\GraphQL\Types\PostType;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\api\GraphQL\Types\VoteType;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -25,35 +28,35 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
* so we'll generate singletons here.
|
||||
* @todo automate this somehow?
|
||||
*/
|
||||
class _TypeRegistry
|
||||
class TypeRegistry
|
||||
{
|
||||
/**
|
||||
* Returns the forum instance
|
||||
*
|
||||
* @var \IPS\forums\api\GraphQL\Types\ForumType
|
||||
* @var ForumType|null
|
||||
*/
|
||||
protected static $forum;
|
||||
protected static ?ForumType $forum = null;
|
||||
|
||||
/**
|
||||
* Returns the post instance
|
||||
*
|
||||
* @var \IPS\forums\api\GraphQL\Types\PostType
|
||||
* @var PostType|null
|
||||
*/
|
||||
protected static $post;
|
||||
protected static ?PostType $post = null;
|
||||
|
||||
/**
|
||||
* Returns the topic instance
|
||||
*
|
||||
* @var \IPS\forums\api\GraphQL\Types\TopicType
|
||||
* @var TopicType|null
|
||||
*/
|
||||
protected static $topic;
|
||||
protected static ?TopicType $topic = null;
|
||||
|
||||
/**
|
||||
* Returns the vote instance
|
||||
*
|
||||
* @var \IPS\forums\api\GraphQL\Types\VoteType
|
||||
* @var VoteType|null
|
||||
*/
|
||||
protected static $vote;
|
||||
protected static ?VoteType $vote = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -66,32 +69,32 @@ class _TypeRegistry
|
||||
/**
|
||||
* @return ForumType
|
||||
*/
|
||||
public static function forum() : \IPS\forums\api\GraphQL\Types\ForumType
|
||||
public static function forum() : ForumType
|
||||
{
|
||||
return self::$forum ?: (self::$forum = new \IPS\forums\api\GraphQL\Types\ForumType());
|
||||
return self::$forum ?: (self::$forum = new ForumType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PostType
|
||||
*/
|
||||
public static function post() : \IPS\forums\api\GraphQL\Types\PostType
|
||||
public static function post() : PostType
|
||||
{
|
||||
return self::$post ?: (self::$post = new \IPS\forums\api\GraphQL\Types\PostType());
|
||||
return self::$post ?: (self::$post = new PostType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TopicType
|
||||
*/
|
||||
public static function topic() : \IPS\forums\api\GraphQL\Types\TopicType
|
||||
public static function topic() : TopicType
|
||||
{
|
||||
return self::$topic ?: (self::$topic = new \IPS\forums\api\GraphQL\Types\TopicType());
|
||||
return self::$topic ?: (self::$topic = new TopicType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return VoteType
|
||||
*/
|
||||
public static function vote() : \IPS\forums\api\GraphQL\Types\VoteType
|
||||
public static function vote() : VoteType
|
||||
{
|
||||
return self::$vote ?: (self::$vote = new \IPS\forums\api\GraphQL\Types\VoteType());
|
||||
return self::$vote ?: (self::$vote = new VoteType());
|
||||
}
|
||||
}
|
||||
@@ -11,53 +11,62 @@
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Types;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\DateTime;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Login;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Api\GraphQL\NodeType;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* ForumType for GraphQL API
|
||||
*/
|
||||
class _ForumType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
class ForumType extends NodeType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $nodeClass = '\IPS\forums\Forum';
|
||||
protected static string $nodeClass = '\IPS\forums\Forum';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'forums_Forum';
|
||||
protected static string $typeName = 'forums_Forum';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A forum';
|
||||
protected static string $typeDescription = 'A forum';
|
||||
|
||||
/*
|
||||
* @brief Follow data passed in to FollowType resolver
|
||||
*/
|
||||
protected static $followData = array('app' => 'forums', 'area' => 'forum');
|
||||
protected static array $followData = array('app' => 'forums', 'area' => 'forum');
|
||||
|
||||
/**
|
||||
* Return the fields available in this type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
public function fields(): array
|
||||
{
|
||||
$defaultFields = parent::fields();
|
||||
$forumFields = array(
|
||||
'solvedEnabled' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($forum) {
|
||||
return ( $forum->forums_bitoptions['bw_enable_answers_member'] || $forum->forums_bitoptions['bw_enable_answers_moderator'] );
|
||||
return ( $forum->forums_bitoptions['bw_solved_set_by_member'] || $forum->forums_bitoptions['bw_solved_set_by_moderator'] );
|
||||
}
|
||||
],
|
||||
'lastPostAuthor' => [
|
||||
@@ -99,7 +108,7 @@ class _ForumType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
'passwordRequired' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($forum) {
|
||||
if( $forum->password === NULL || \IPS\Member::loggedIn()->inGroup( explode( ',', $forum->password_override ) ) )
|
||||
if( $forum->password === NULL || Member::loggedIn()->inGroup( explode( ',', $forum->password_override ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -129,7 +138,7 @@ class _ForumType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public static function getItemType()
|
||||
public static function getItemType(): ObjectType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -137,34 +146,34 @@ class _ForumType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
/**
|
||||
* Check for a password before returning items
|
||||
*
|
||||
* @param \IPS\forums\Forum
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return array
|
||||
* @param Model $forum
|
||||
* @param array $args Arguments passed to this resolver
|
||||
* @return int|ActiveRecordIterator
|
||||
*/
|
||||
protected static function items($forum, $args)
|
||||
protected static function items( Model $forum, array $args): int|ActiveRecordIterator
|
||||
{
|
||||
// If there's no password or our group is excluded, just continue
|
||||
if( $forum->password === NULL || \IPS\Member::loggedIn()->inGroup( explode( ',', $forum->password_override ) ) )
|
||||
if( $forum->password === NULL || Member::loggedIn()->inGroup( explode( ',', $forum->password_override ) ) )
|
||||
{
|
||||
return parent::items($forum, $args);
|
||||
return parent::items( $forum, $args );
|
||||
}
|
||||
|
||||
if( !isset( $args['password'] ) || !\IPS\Login::compareHashes( md5( $forum->password ), md5( $args['password'] ) ) )
|
||||
if( !isset( $args['password'] ) || !Login::compareHashes( md5( $forum->password ), md5( $args['password'] ) ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INCORRECT_PASSWORD', 'GQL/0002/1', 403 );
|
||||
throw new SafeException( 'INCORRECT_PASSWORD', 'GQL/0002/1', 403 );
|
||||
}
|
||||
|
||||
return parent::items($forum, $args);
|
||||
return parent::items( $forum, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve last post author field
|
||||
*
|
||||
* @param \IPS\forums\Forum
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return array
|
||||
* @param Forum $forum
|
||||
* @param array $args Arguments passed to this resolver
|
||||
* @return Member|null
|
||||
*/
|
||||
protected static function lastPostAuthor($forum, $args)
|
||||
protected static function lastPostAuthor( Forum $forum, array $args) : Member|null
|
||||
{
|
||||
$lastComment = $forum->lastPost();
|
||||
|
||||
@@ -179,11 +188,11 @@ class _ForumType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
/**
|
||||
* Resolve last post date field
|
||||
*
|
||||
* @param \IPS\forums\Forum
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return array
|
||||
* @param Forum $forum
|
||||
* @param array $args Arguments passed to this resolver
|
||||
* @return int|DateTime|null
|
||||
*/
|
||||
protected static function lastPostDate($forum, $args)
|
||||
protected static function lastPostDate( Forum $forum, array $args ) : int|DateTime|null
|
||||
{
|
||||
$lastComment = $forum->lastPost();
|
||||
|
||||
|
||||
@@ -12,40 +12,44 @@
|
||||
namespace IPS\forums\api\GraphQL\Types;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\CommentType;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\Member;
|
||||
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 _PostType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
class PostType extends CommentType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $commentClass = '\IPS\forums\Topic\Post';
|
||||
protected static string $commentClass = '\IPS\forums\Topic\Post';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'forums_Post';
|
||||
protected static string $typeName = 'forums_Post';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A post';
|
||||
protected static string $typeDescription = 'A post';
|
||||
|
||||
/**
|
||||
* Get the item type that goes with this item type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public static function getItemType()
|
||||
public static function getItemType(): ObjectType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -55,7 +59,7 @@ class _PostType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
public function fields(): array
|
||||
{
|
||||
$defaultFields = parent::fields();
|
||||
$postFields = array(
|
||||
@@ -65,14 +69,6 @@ class _PostType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
return $post->item();
|
||||
}
|
||||
],
|
||||
/* Q&A STUFF */
|
||||
'isQuestion' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => "Boolean indicating whether this post is a question, i.e. the first post in a question topic",
|
||||
'resolve' => function ($post) {
|
||||
return $post->item()->isQuestion() && $post->new_topic;
|
||||
}
|
||||
],
|
||||
'answerVotes' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'resolve' => function ($post) {
|
||||
@@ -85,41 +81,6 @@ class _PostType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
'resolve' => function ($post) {
|
||||
return $post->post_bwoptions['best_answer'];
|
||||
}
|
||||
],
|
||||
'canVoteUp' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($post) {
|
||||
if( !$post->item()->isQuestion() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $post->canVote(1);
|
||||
}
|
||||
],
|
||||
'canVoteDown' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($post) {
|
||||
if( !$post->item()->isQuestion() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $post->canVote(-1) && \IPS\Settings::i()->forums_questions_downvote;
|
||||
}
|
||||
],
|
||||
'vote' => [
|
||||
'type' => \IPS\forums\api\GraphQL\TypeRegistry::vote(),
|
||||
'resolve' => function ($post) {
|
||||
$ratings = $post->item()->answerVotes( \IPS\Member::loggedIn() );
|
||||
|
||||
if( !$post->item()->isQuestion() || !isset( $ratings[ $post->pid ] ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $ratings[ $post->pid ] === -1 ? 'DOWN' : 'UP';
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
@@ -132,11 +93,13 @@ class _PostType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
/**
|
||||
* Return the definite article, but without the item type
|
||||
*
|
||||
* @return string
|
||||
* @param Comment $post
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public static function definiteArticleNoItem($post, $options = array())
|
||||
public static function definiteArticleNoItem( Comment $post, array $options = array() ): string
|
||||
{
|
||||
$type = $post->item()->isQuestion() ? 'answer_lc' : 'post_lc';
|
||||
return \IPS\Member::loggedIn()->language()->addToStack($type, FALSE, $options);
|
||||
$type = 'post_lc';
|
||||
return Member::loggedIn()->language()->addToStack( $type, FALSE, $options);
|
||||
}
|
||||
}
|
||||
@@ -10,48 +10,53 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Types;
|
||||
use Exception;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\_TypeRegistry;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\ItemType;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Member;
|
||||
use function defined;
|
||||
use function in_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* TopicType for GraphQL API
|
||||
*/
|
||||
class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
class TopicType extends ItemType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $itemClass = '\IPS\forums\Topic';
|
||||
protected static string $itemClass = '\IPS\forums\Topic';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'forums_Topic';
|
||||
protected static string $typeName = 'forums_Topic';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A topic';
|
||||
protected static string $typeDescription = 'A topic';
|
||||
|
||||
/*
|
||||
* @brief Follow data passed in to FollowType resolver
|
||||
*/
|
||||
protected static $followData = array('app' => 'forums', 'area' => 'topic');
|
||||
protected static array $followData = array('app' => 'forums', 'area' => 'topic');
|
||||
|
||||
/**
|
||||
* Return the fields available in this type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
public function fields(): array
|
||||
{
|
||||
// Extend our fields with topic-specific stuff
|
||||
$defaultFields = parent::fields();
|
||||
@@ -73,7 +78,7 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
'resolve' => function ($topic) {
|
||||
foreach( $topic->stats(FALSE) as $k => $v )
|
||||
{
|
||||
if( \in_array( $k, $topic->hotStats ) )
|
||||
if( in_array( $k, $topic->hotStats ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -96,6 +101,7 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
if( $topic->isSolved() ){
|
||||
return $topic->mapped('solved_comment_id');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
],
|
||||
'canMarkSolved' => [
|
||||
@@ -114,69 +120,14 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
|
||||
try
|
||||
{
|
||||
$solved = \IPS\forums\Topic\Post::load( $topic->mapped('solved_comment_id') );
|
||||
return $solved;
|
||||
return Post::load( $topic->mapped('solved_comment_id') );
|
||||
}
|
||||
catch (\Exception $err)
|
||||
catch (Exception $err)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
/* Q&A STUFF */
|
||||
'isQuestion' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($topic) {
|
||||
return $topic->isQuestion();
|
||||
}
|
||||
],
|
||||
'questionVotes' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'resolve' => function ($topic) {
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return \intval( $topic->question_rating );
|
||||
}
|
||||
],
|
||||
'canVoteUp' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($topic) {
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $topic->canVote(1);
|
||||
}
|
||||
],
|
||||
'canVoteDown' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($topic) {
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $topic->canVote(-1) && \IPS\Settings::i()->forums_questions_downvote;
|
||||
}
|
||||
],
|
||||
'vote' => [
|
||||
'type' => \IPS\forums\api\GraphQL\TypeRegistry::vote(),
|
||||
'resolve' => function ($topic) {
|
||||
$topicVotes = $topic->votes();
|
||||
|
||||
if( !$topic->isQuestion() || !isset( $topicVotes[ \IPS\Member::loggedIn()->member_id ] ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $topicVotes[ \IPS\Member::loggedIn()->member_id ] === -1 ? 'DOWN' : 'UP';
|
||||
}
|
||||
],
|
||||
'hasBestAnswer' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($topic) {
|
||||
@@ -186,11 +137,6 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
'bestAnswerID' => [
|
||||
'type' => TypeRegistry::id(),
|
||||
'resolve' => function ($topic) {
|
||||
if( !$topic->isQuestion() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $topic->topic_answered_pid;
|
||||
}
|
||||
],
|
||||
@@ -208,7 +154,7 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
$topicFields['postCount']['resolve'] = function ($topic, $args) {
|
||||
if( $args['includeHidden'] )
|
||||
{
|
||||
return $topic->commentCount() + ( $topic->isQuestion() ? 1 : 0 );
|
||||
return $topic->commentCount();
|
||||
}
|
||||
|
||||
return $topic->mapped('num_comments');
|
||||
@@ -230,7 +176,7 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
return array_merge( $defaultFields, $topicFields );
|
||||
}
|
||||
|
||||
public static function args()
|
||||
public static function args(): array
|
||||
{
|
||||
return array_merge( parent::args(), array(
|
||||
'password' => [
|
||||
@@ -244,15 +190,15 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
* Here we adjust the resolver for the commentInformation field to check whether this is
|
||||
* a poll-only topic.
|
||||
*
|
||||
* @return string|null
|
||||
* @return array
|
||||
*/
|
||||
public static function getItemPermissionFields()
|
||||
public static function getItemPermissionFields(): array
|
||||
{
|
||||
$defaultFields = parent::getItemPermissionFields();
|
||||
$existingResolver = $defaultFields['commentInformation']['resolve'];
|
||||
|
||||
$defaultFields['commentInformation']['resolve'] = function ($topic, $args, $context) use ( $existingResolver ) {
|
||||
if( $topic->canComment( \IPS\Member::loggedIn(), FALSE ) && ( $topic->getPoll() and $topic->getPoll()->poll_only ) )
|
||||
if( $topic->canComment( Member::loggedIn(), FALSE ) && ( $topic->getPoll() and $topic->getPoll()->poll_only ) )
|
||||
{
|
||||
return 'topic_poll_can_comment';
|
||||
}
|
||||
@@ -270,7 +216,7 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderByOptions()
|
||||
public static function getOrderByOptions(): array
|
||||
{
|
||||
$defaultArgs = parent::getOrderByOptions();
|
||||
return array_merge( $defaultArgs, array('last_comment', 'num_comments', 'views', 'author_name', 'last_comment_name', 'date', 'votes') );
|
||||
@@ -281,39 +227,8 @@ class _TopicType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
protected static function getCommentType()
|
||||
protected static function getCommentType(): ObjectType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the comments field - overridden from ItemType
|
||||
* If this is a question and order isn't date, then force order by votes
|
||||
*
|
||||
* @param \IPS\forums\Topic
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return array
|
||||
*/
|
||||
protected static function comments($topic, $args)
|
||||
{
|
||||
if( $topic->isQuestion() && $args['orderBy'] !== 'date' )
|
||||
{
|
||||
if( $topic->isArchived() )
|
||||
{
|
||||
$args['orderBy'] = "archive_is_first desc, archive_bwoptions";
|
||||
$args['orderDir'] = "DESC";
|
||||
}
|
||||
else
|
||||
{
|
||||
$args['orderBy'] = "new_topic DESC, post_bwoptions DESC, post_field_int DESC, post_date";
|
||||
$args['orderDir'] = "ASC";
|
||||
}
|
||||
}
|
||||
elseif( !$topic->isQuestion() && $args['orderBy'] === 'votes' )
|
||||
{
|
||||
$args['orderBy'] = 'date'; // Only Q&A can order by votes
|
||||
}
|
||||
|
||||
return parent::comments($topic, $args);
|
||||
}
|
||||
}
|
||||
@@ -10,24 +10,24 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Types;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* VoteType for GraphQL API
|
||||
*/
|
||||
class _VoteType extends \GraphQL\Type\Definition\EnumType
|
||||
class VoteType extends EnumType
|
||||
{
|
||||
/**
|
||||
* Get object type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -12,21 +12,35 @@
|
||||
namespace IPS\forums\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\Data\Store;
|
||||
use IPS\forums\Forum;
|
||||
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;
|
||||
|
||||
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 Forums API
|
||||
*/
|
||||
class _forums extends \IPS\Node\Api\NodeController
|
||||
class forums extends NodeController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Forum';
|
||||
protected string $class = 'IPS\forums\Forum';
|
||||
|
||||
/**
|
||||
* GET /forums/forums
|
||||
@@ -36,9 +50,10 @@ class _forums 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 forums the authorized user can view will be included
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\forums\Forum>
|
||||
* @apireturn PaginatedResponse<IPS\forums\Forum>
|
||||
* @return PaginatedResponse<Forum>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Return */
|
||||
return $this->_list();
|
||||
@@ -50,17 +65,18 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 1F363/1 INVALID_ID The forum does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\forums\Forum
|
||||
* @apireturn \IPS\forums\Forum
|
||||
* @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', '1F363/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '1F363/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +87,7 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
* @apiclientonly
|
||||
* @reqapiparam string title The forum title
|
||||
* @apiparam string description The forum description
|
||||
* @apiparam string type normal|qa|redirect|category
|
||||
* @apiparam string type normal|redirect|category
|
||||
* @apiparam int|null parent The ID number of the parent the forum should be created in. NULL for root.
|
||||
* @apiparam string password Forum password
|
||||
* @apiparam int theme Theme to use as an override
|
||||
@@ -80,19 +96,25 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int can_see_others 0|1 Users can see topics posted by other users?
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, reply, attachments) 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)
|
||||
* @apiparam string redirect_url If creating a redirect forum, the URL to redirect to.
|
||||
* @return \IPS\forums\Forum
|
||||
* @apireturn \IPS\forums\Forum
|
||||
* @throws 1F363/2 NO_TITLE A title for the forum must be supplied
|
||||
* @throws 1F363/3 NO_REDIRECT_URL No redirect URL supplied.
|
||||
* @throws 1F363/4 INVALID_TYPE Invalid type of forum.
|
||||
* @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', '1F363/2', 400 );
|
||||
throw new Exception( 'NO_TITLE', '1F363/2', 400 );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
if ( !Request::i()->parent )
|
||||
{
|
||||
Request::i()->parent = -1;
|
||||
}
|
||||
|
||||
return new Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +124,7 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
* @apiclientonly
|
||||
* @reqapiparam string title The forum title
|
||||
* @apiparam string description The forum description
|
||||
* @apiparam string type normal|qa|redirect|category
|
||||
* @apiparam string type normal|redirect|category
|
||||
* @apiparam int|null parent The ID number of the parent the forum should be created in. NULL for root.
|
||||
* @apiparam string password Forum password
|
||||
* @apiparam int theme Theme to use as an override
|
||||
@@ -112,16 +134,18 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, reply, attachments) 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)
|
||||
* @apiparam string redirect_url If editing a redirect forum, the URL to redirect too.
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\forums\Forum
|
||||
* @apireturn \IPS\forums\Forum
|
||||
* @throws 1F363/3 NO_REDIRECT_URL No redirect URL supplied.
|
||||
* @throws 1F363/4 INVALID_TYPE Invalid type of forum.
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
/* @var Forum $class */
|
||||
$class = $this->class;
|
||||
$forum = $class::load( $id );
|
||||
|
||||
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $forum )->apiOutput( $this->member ) );
|
||||
|
||||
return new Response( 200, $this->_createOrUpdate( $forum )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,54 +155,82 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
* @apiclientonly
|
||||
* @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 );
|
||||
/* Load forum and verify that it is not used for comments */
|
||||
/* @var Forum $nodeClass */
|
||||
$nodeClass = $this->class;
|
||||
if ( Request::i()->subnode )
|
||||
{
|
||||
$nodeClass = $nodeClass::$subnodeClass;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$node = $nodeClass::load( $id );
|
||||
}
|
||||
catch (OutOfRangeException $e )
|
||||
{
|
||||
throw new Exception( 'INVALID_ID', '2F363/8', 404 );
|
||||
}
|
||||
|
||||
if ( $dbCategory = $node->isUsedByADownloadsCategory() )
|
||||
{
|
||||
throw new Exception( 'FORUM_USED_BY_DOWNLOADS', '2F363/9', 403 );
|
||||
}
|
||||
|
||||
if ( $db = $node->isUsedByCms() )
|
||||
{
|
||||
throw new Exception( 'FORUM_USED_BY_DATABASE', '2F363/6', 403 );
|
||||
}
|
||||
|
||||
return $this->_delete( $id, Request::i()->deleteChildrenOrMove ?? NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update node
|
||||
*
|
||||
* @param \IPS\Node\Model $forum The node
|
||||
* @return \IPS\Node\Model
|
||||
* @param Model $forum The node
|
||||
* @return Model
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\Node\Model $forum )
|
||||
protected function _createOrUpdate( Model $forum ): Model
|
||||
{
|
||||
foreach ( array( 'title' => "forums_forum_{$forum->id}", 'description' => "forums_forum_{$forum->id}_desc" ) as $fieldKey => $langKey )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$fieldKey ) )
|
||||
if ( isset( Request::i()->$fieldKey ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'forums', $langKey, \IPS\Request::i()->$fieldKey );
|
||||
Lang::saveCustom( 'forums', $langKey, Request::i()->$fieldKey );
|
||||
|
||||
if ( $fieldKey === 'title' )
|
||||
{
|
||||
$forum->name_seo = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->$fieldKey );
|
||||
$forum->name_seo = Friendly::seoTitle( Request::i()->$fieldKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( \IPS\Request::i()->parent ) )
|
||||
if( isset( Request::i()->parent ) )
|
||||
{
|
||||
$forum->parent_id = (int) \IPS\Request::i()->parent ?: -1;
|
||||
$forum->parent_id = (int) Request::i()->parent ?: -1;
|
||||
|
||||
if ( !isset( \IPS\Request::i()->type ) )
|
||||
if ( !isset( Request::i()->type ) )
|
||||
{
|
||||
if ( $forum->parent_id === -1 )
|
||||
{
|
||||
\IPS\Request::i()->type = 'category';
|
||||
Request::i()->type = 'category';
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Request::i()->type = 'normal';
|
||||
Request::i()->type = 'normal';
|
||||
}
|
||||
}
|
||||
|
||||
switch ( \IPS\Request::i()->type )
|
||||
switch ( Request::i()->type )
|
||||
{
|
||||
case 'category':
|
||||
$forum->sub_can_post = 0;
|
||||
@@ -189,54 +241,49 @@ class _forums extends \IPS\Node\Api\NodeController
|
||||
$forum->sub_can_post = 1;
|
||||
break;
|
||||
|
||||
case 'qa':
|
||||
case 'questions':
|
||||
$forum->forums_bitoptions['bw_enable_answers'] = TRUE;
|
||||
break;
|
||||
|
||||
case 'redirect':
|
||||
if ( !isset( \IPS\Request::i()->redirect_url ) )
|
||||
if ( !isset( Request::i()->redirect_url ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_REDIRECT_URL', '1F363/3', 400 );
|
||||
throw new Exception( 'NO_REDIRECT_URL', '1F363/3', 400 );
|
||||
}
|
||||
|
||||
$forum->redirect_on = 1;
|
||||
$forum->redirect_url = \IPS\Request::i()->redirect_url;
|
||||
$forum->redirect_url = Request::i()->redirect_url;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \IPS\Api\Exception( 'INVALID_TYPE', '1F363/4', 400 );
|
||||
throw new Exception( 'INVALID_TYPE', '1F363/4', 400 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->password ) )
|
||||
if ( isset( Request::i()->password ) )
|
||||
{
|
||||
$forum->password = \IPS\Request::i()->password;
|
||||
$forum->password = Request::i()->password;
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->theme ) )
|
||||
if ( isset( Request::i()->theme ) )
|
||||
{
|
||||
$forum->skin_id = \IPS\Request::i()->theme;
|
||||
$forum->skin_id = Request::i()->theme;
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->sitemap_priority ) )
|
||||
if ( isset( Request::i()->sitemap_priority ) )
|
||||
{
|
||||
$forum->ipseo_priority = \IPS\Request::i()->sitemap_priority;
|
||||
$forum->ipseo_priority = Request::i()->sitemap_priority;
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->min_content ) )
|
||||
if ( isset( Request::i()->min_content ) )
|
||||
{
|
||||
$forum->min_content = \IPS\Request::i()->min_content;
|
||||
$forum->min_content = Request::i()->min_content;
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->can_see_others ) )
|
||||
if ( isset( Request::i()->can_see_others ) )
|
||||
{
|
||||
$forum->can_view_others = \IPS\Request::i()->can_see_others;
|
||||
$forum->can_view_others = Request::i()->can_see_others;
|
||||
}
|
||||
|
||||
$forum = parent::_createOrUpdate( $forum );
|
||||
|
||||
unset( \IPS\Data\Store::i()->forumsCustomNodes );
|
||||
unset( Store::i()->forumsCustomNodes );
|
||||
|
||||
return $forum;
|
||||
}
|
||||
|
||||
@@ -12,21 +12,35 @@
|
||||
namespace IPS\forums\api;
|
||||
|
||||
/* To prevent 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\Content\Api\CommentController;
|
||||
use IPS\Db;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
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 Posts API
|
||||
*/
|
||||
class _posts extends \IPS\Content\Api\CommentController
|
||||
class posts extends CommentController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic\Post';
|
||||
protected string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/**
|
||||
* GET /forums/posts
|
||||
@@ -46,17 +60,18 @@ class _posts 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\forums\Topic\Post>
|
||||
* @apireturn PaginatedResponse<IPS\forums\Topic\Post>
|
||||
* @return PaginatedResponse<Post>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Init */
|
||||
$where = array();
|
||||
|
||||
/* Has best answer */
|
||||
if ( isset( \IPS\Request::i()->hasBestAnswer ) )
|
||||
if ( isset( Request::i()->hasBestAnswer ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->hasBestAnswer )
|
||||
if ( Request::i()->hasBestAnswer )
|
||||
{
|
||||
$where[] = array( "topic_answered_pid>0" );
|
||||
}
|
||||
@@ -67,15 +82,15 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
}
|
||||
|
||||
/* Archived */
|
||||
if ( isset( \IPS\Request::i()->archived ) )
|
||||
if ( isset( Request::i()->archived ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->archived )
|
||||
if ( Request::i()->archived )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'topic_archive_status', array( \IPS\forums\Topic::ARCHIVE_DONE, \IPS\forums\Topic::ARCHIVE_WORKING, \IPS\forums\Topic::ARCHIVE_RESTORE ) ) );
|
||||
$where[] = array( Db::i()->in( 'topic_archive_status', array( Topic::ARCHIVE_DONE, Topic::ARCHIVE_WORKING, Topic::ARCHIVE_RESTORE ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'topic_archive_status', array( \IPS\forums\Topic::ARCHIVE_NOT, \IPS\forums\Topic::ARCHIVE_EXCLUDE ) ) );
|
||||
$where[] = array( Db::i()->in( 'topic_archive_status', array( Topic::ARCHIVE_NOT, Topic::ARCHIVE_EXCLUDE ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,12 +104,14 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 1F295/4 INVALID_ID The post ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @apireturn \IPS\forums\Topic\Post
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var Post $class */
|
||||
$class = $this->class;
|
||||
if ( $this->member )
|
||||
{
|
||||
@@ -105,11 +122,11 @@ class _posts 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', '1F295/4', 404 );
|
||||
throw new Exception( 'INVALID_ID', '1F295/4', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,14 +137,15 @@ class _posts 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\forums\Topic\Post
|
||||
* @apireturn \IPS\forums\Topic\Post
|
||||
* @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 );
|
||||
}
|
||||
@@ -138,13 +156,14 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author ID of the member who reacted
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @apireturn \IPS\forums\Topic\Post
|
||||
* @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 );
|
||||
}
|
||||
@@ -167,18 +186,19 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
* @throws 1F295/3 NO_POST No post was supplied
|
||||
* @throws 2F294/A NO_PERMISSION The authorized user does not have permission to reply to that topic
|
||||
* @throws 3F295/C NO_ANON_PERMISSION The topic is set for anonymous posting, but the author does not have permission to post anonymously
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @apireturn \IPS\forums\Topic\Post
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTindex()
|
||||
public function POSTindex(): Response
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::load( \IPS\Request::i()->topic );
|
||||
$topic = Topic::load( Request::i()->topic );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TOPIC', '1F295/1', 403 );
|
||||
throw new Exception( 'NO_TOPIC', '1F295/1', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
@@ -186,47 +206,47 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
if ( !$topic->canComment( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/A', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2F294/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', '1F295/2', 403 );
|
||||
throw new Exception( 'NO_AUTHOR', '1F295/2', 403 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \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', '1F295/2', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1F295/2', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check anonymous posting */
|
||||
if ( isset( \IPS\Request::i()->anonymous ) and $author->member_id )
|
||||
if ( isset( Request::i()->anonymous ) and $author->member_id )
|
||||
{
|
||||
if ( ! $topic->container()->canPostAnonymously( 0, $author ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_ANON_PERMISSION', '3F295/C', 403 );
|
||||
throw new Exception( 'NO_ANON_PERMISSION', '3F295/C', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
if ( !\IPS\Request::i()->post )
|
||||
if ( !Request::i()->post )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_POST', '1F295/3', 403 );
|
||||
throw new Exception( 'NO_POST', '1F295/3', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
@@ -249,33 +269,34 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
* @throws 1F295/8 CANNOT_HIDE_FIRST_POST You cannot hide or unhide the first post in a topic. Hide/unhide the topic itself instead.
|
||||
* @throws 1F295/9 CANNOT_AUTHOR_FIRST_POST You cannot change the author for the first post in a topic. Change the author on the topic itself instead.
|
||||
* @throws 2F295/A NO_PERMISSION The authorized user does not have permission to edit the post
|
||||
* @return \IPS\forums\Topic\Post
|
||||
* @apireturn \IPS\forums\Topic\Post
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Load */
|
||||
$post = \IPS\forums\Topic\Post::load( $id );
|
||||
$post = Post::load( $id );
|
||||
if ( $this->member and !$post->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
if ( $this->member and !$post->canEdit( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F295/A', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2F295/A', 403 );
|
||||
}
|
||||
|
||||
/* Check */
|
||||
if ( $post->isFirst() )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->hidden ) )
|
||||
if ( isset( Request::i()->hidden ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'CANNOT_HIDE_FIRST_POST', '1F295/8', 403 );
|
||||
throw new Exception( 'CANNOT_HIDE_FIRST_POST', '1F295/8', 403 );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->author ) )
|
||||
if ( isset( Request::i()->author ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'CANNOT_AUTHOR_FIRST_POST', '1F295/9', 403 );
|
||||
throw new Exception( 'CANNOT_AUTHOR_FIRST_POST', '1F295/9', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,14 +305,14 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
return $this->_edit( $post, 'post' );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
catch ( InvalidArgumentException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '2F295/7', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '2F295/7', 400 );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2F295/6', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2F295/6', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,29 +324,31 @@ class _posts extends \IPS\Content\Api\CommentController
|
||||
* @throws 1F295/5 INVALID_ID The post ID does not exist
|
||||
* @throws 1F295/B CANNOT_DELETE_FIRST_POST You cannot delete the first post in a topic. Delete the topic itself instead.
|
||||
* @throws 2F295/B NO_PERMISSION The authorized user does not have permission to delete the post
|
||||
* @return void
|
||||
* @apireturn void
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
public function DELETEitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var Post $class */
|
||||
$class = $this->class;
|
||||
$object = $class::load( $id );
|
||||
if ( $object->isFirst() )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'CANNOT_DELETE_FIRST_POST', '1F295/B', 403 );
|
||||
throw new Exception( 'CANNOT_DELETE_FIRST_POST', '1F295/B', 403 );
|
||||
}
|
||||
if ( $this->member and !$object->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F295/B', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2F295/B', 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', '1F295/5', 404 );
|
||||
throw new Exception( 'INVALID_ID', '1F295/5', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,9 +362,10 @@ class _posts 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\forums\Topic\Post
|
||||
* @apireturn \IPS\forums\Topic\Post
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem_report( $id )
|
||||
public function POSTitem_report( int $id ): Response
|
||||
{
|
||||
return $this->_report( $id );
|
||||
}
|
||||
|
||||
@@ -12,21 +12,37 @@
|
||||
namespace IPS\forums\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\Content\Api\ItemController;
|
||||
use IPS\Content\Item;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
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 Topics API
|
||||
*/
|
||||
class _topics extends \IPS\Content\Api\ItemController
|
||||
class topics extends ItemController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic';
|
||||
protected string $class = 'IPS\forums\Topic';
|
||||
|
||||
/**
|
||||
* GET /forums/topics
|
||||
@@ -47,17 +63,18 @@ class _topics 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\forums\Topic>
|
||||
* @apireturn PaginatedResponse<IPS\forums\Topic>
|
||||
* @return PaginatedResponse<Topic>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Init */
|
||||
$where = array();
|
||||
|
||||
/* Has best answer */
|
||||
if ( isset( \IPS\Request::i()->hasBestAnswer ) )
|
||||
if ( isset( Request::i()->hasBestAnswer ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->hasBestAnswer )
|
||||
if ( Request::i()->hasBestAnswer )
|
||||
{
|
||||
$where[] = array( "topic_answered_pid>0" );
|
||||
}
|
||||
@@ -68,15 +85,15 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
}
|
||||
|
||||
/* Archived */
|
||||
if ( isset( \IPS\Request::i()->archived ) )
|
||||
if ( isset( Request::i()->archived ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->archived )
|
||||
if ( Request::i()->archived )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'topic_archive_status', array( \IPS\forums\Topic::ARCHIVE_DONE, \IPS\forums\Topic::ARCHIVE_WORKING, \IPS\forums\Topic::ARCHIVE_RESTORE ) ) );
|
||||
$where[] = array( Db::i()->in( 'topic_archive_status', array( Topic::ARCHIVE_DONE, Topic::ARCHIVE_WORKING, Topic::ARCHIVE_RESTORE ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'topic_archive_status', array( \IPS\forums\Topic::ARCHIVE_NOT, \IPS\forums\Topic::ARCHIVE_EXCLUDE ) ) );
|
||||
$where[] = array( Db::i()->in( 'topic_archive_status', array( Topic::ARCHIVE_NOT, Topic::ARCHIVE_EXCLUDE ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,17 +107,18 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2F294/9 INVALID_ID The topic ID does not exist
|
||||
* @return \IPS\forums\Topic
|
||||
* @apireturn \IPS\forums\Topic
|
||||
* @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', '2F294/9', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2F294/9', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,37 +132,38 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @throws 1F294/1 INVALID_ID The topic ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\forums\Topic\Post>
|
||||
* @apireturn PaginatedResponse<IPS\forums\Topic\Post>
|
||||
* @return PaginatedResponse<Post>
|
||||
*/
|
||||
public function GETitem_posts( $id )
|
||||
public function GETitem_posts( int $id ): PaginatedResponse
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_comments( $id, 'IPS\forums\Topic\Post' );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '1F294/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '1F294/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update topic
|
||||
*
|
||||
* @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
|
||||
{
|
||||
/* Open/Close time */
|
||||
if ( \IPS\Request::i()->open_time )
|
||||
if ( Request::i()->open_time )
|
||||
{
|
||||
$item->topic_open_time = ( new \DateTime( \IPS\Request::i()->open_time ) )->getTimestamp();
|
||||
$item->topic_open_time = ( new \DateTime( Request::i()->open_time ) )->getTimestamp();
|
||||
}
|
||||
if ( \IPS\Request::i()->close_time )
|
||||
if ( Request::i()->close_time )
|
||||
{
|
||||
$item->topic_close_time = ( new \DateTime( \IPS\Request::i()->close_time ) )->getTimestamp();
|
||||
$item->topic_close_time = ( new \DateTime( Request::i()->close_time ) )->getTimestamp();
|
||||
}
|
||||
|
||||
/* Do we have a poll to attach? */
|
||||
@@ -184,22 +203,23 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
* @throws 1F294/4 NO_POST No post was supplied
|
||||
* @throws 2F294/C NO_PERMISSION The authorized user does not have permission to create a topic in that forum
|
||||
* @throws 3F294/D NO_ANON_PERMISSION The topic is set for anonymous posting, but the author does not have permission to post anonymously
|
||||
* @return \IPS\forums\Topic
|
||||
* @apireturn \IPS\forums\Topic
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTindex()
|
||||
public function POSTindex(): Response
|
||||
{
|
||||
/* Get forum */
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::load( \IPS\Request::i()->forum );
|
||||
$forum = Forum::load( Request::i()->forum );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_FORUM', '1F294/2', 400 );
|
||||
throw new Exception( 'NO_FORUM', '1F294/2', 400 );
|
||||
}
|
||||
if ( !$forum->sub_can_post )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/C', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2F294/C', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
@@ -207,55 +227,55 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
{
|
||||
if ( !$forum->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/C', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2F294/C', 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', '1F294/3', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1F294/3', 400 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \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', '1F294/3', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1F294/3', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check anonymous posting */
|
||||
if ( isset( \IPS\Request::i()->anonymous ) and $author->member_id )
|
||||
if ( isset( Request::i()->anonymous ) and $author->member_id )
|
||||
{
|
||||
if ( ! $forum->canPostAnonymously( 0, $author ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_ANON_PERMISSION', '3F294/D', 403 );
|
||||
throw new Exception( 'NO_ANON_PERMISSION', '3F294/D', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a title and a post */
|
||||
if ( !\IPS\Request::i()->title )
|
||||
if ( !Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '1F294/5', 400 );
|
||||
throw new Exception( 'NO_TITLE', '1F294/5', 400 );
|
||||
}
|
||||
if ( !\IPS\Request::i()->post )
|
||||
if ( !Request::i()->post )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_POST', '1F294/4', 400 );
|
||||
throw new Exception( 'NO_POST', '1F294/4', 400 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
return new \IPS\Api\Response( 201, $this->_create( $forum, $author )->apiOutput( $this->member ) );
|
||||
return new Response( 201, $this->_create( $forum, $author )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,52 +308,53 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
* @throws 1F294/8 NO_AUTHOR The author ID does not exist
|
||||
* @throws 2F294/A NO_PERMISSION The authorized user does not have permission to edit the topic
|
||||
* @throws 1F294/E INVALID_DATE The date is invalid
|
||||
* @return \IPS\forums\Topic
|
||||
* @apireturn \IPS\forums\Topic
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::load( $id );
|
||||
$topic = Topic::load( $id );
|
||||
if ( $this->member and !$topic->can( 'read', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
if ( $this->member and !$topic->canEdit( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/A', 403 );
|
||||
throw new Exception( 'NO_PERMISSION', '2F294/A', 403 );
|
||||
}
|
||||
|
||||
/* New forum */
|
||||
if ( isset( \IPS\Request::i()->forum ) and \IPS\Request::i()->forum != $topic->forum_id and ( !$this->member or $topic->canMove( $this->member ) ) )
|
||||
if ( isset( Request::i()->forum ) and Request::i()->forum != $topic->forum_id and ( !$this->member or $topic->canMove( $this->member ) ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$newForum = \IPS\forums\Forum::load( \IPS\Request::i()->forum );
|
||||
$newForum = Forum::load( Request::i()->forum );
|
||||
if ( $this->member and !$newForum->can( 'add', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
$topic->move( $newForum );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_FORUM', '1F294/7', 400 );
|
||||
throw new Exception( 'NO_FORUM', '1F294/7', 400 );
|
||||
}
|
||||
}
|
||||
|
||||
/* New author */
|
||||
if ( !$this->member and isset( \IPS\Request::i()->author ) )
|
||||
if ( !$this->member and isset( Request::i()->author ) )
|
||||
{
|
||||
/* Just renaming the guest */
|
||||
if ( !$topic->starter_id and ( !isset( \IPS\Request::i()->author ) or !\IPS\Request::i()->author ) and isset( \IPS\Request::i()->author_name ) )
|
||||
if ( !$topic->starter_id and ( !isset( Request::i()->author ) or !Request::i()->author ) and isset( Request::i()->author_name ) )
|
||||
{
|
||||
$topic->starter_name = \IPS\Request::i()->author_name;
|
||||
$topic->starter_name = Request::i()->author_name;
|
||||
|
||||
if ( $firstPost = $this->comments( 1, 0, 'date', 'asc' ) )
|
||||
if ( $firstPost = $topic->comments( 1, 0, 'date', 'asc' ) )
|
||||
{
|
||||
$firstPost->author_name = \IPS\Request::i()->author_name;
|
||||
$firstPost->author_name = Request::i()->author_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,31 +363,31 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
$topic->changeAuthor( $member );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1F294/8', 400 );
|
||||
throw new Exception( 'NO_AUTHOR', '1F294/8', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Do we have a date? */
|
||||
if ( isset( \IPS\Request::i()->date ) ) {
|
||||
if ( isset( Request::i()->date ) ) {
|
||||
|
||||
try
|
||||
{
|
||||
$date = new \IPS\DateTime( \IPS\Request::i()->date );
|
||||
$date = new DateTime( Request::i()->date );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_DATE', '1F294/E', 400 );
|
||||
throw new Exception( 'INVALID_DATE', '1F294/E', 400 );
|
||||
}
|
||||
|
||||
/* Do we have a first comment? */
|
||||
@@ -374,6 +395,7 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var array $databaseColumnMap */
|
||||
$commentClass = $topic::$commentClass;
|
||||
$field = $commentClass::$databaseColumnMap['date'];
|
||||
|
||||
@@ -390,11 +412,11 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
|
||||
/* Save and return */
|
||||
$topic->save();
|
||||
return new \IPS\Api\Response( 200, $topic->apiOutput( $this->member ) );
|
||||
return new Response( 200, $topic->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2F294/6', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2F294/6', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,25 +427,26 @@ class _topics extends \IPS\Content\Api\ItemController
|
||||
* @param int $id ID Number
|
||||
* @throws 1F294/5 INVALID_ID The topic ID does not exist
|
||||
* @throws 2F294/B NO_PERMISSION The authorized user does not have permission to delete the topic
|
||||
* @return void
|
||||
* @apireturn void
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
public function DELETEitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$item = \IPS\forums\Topic::load( $id );
|
||||
$item = Topic::load( $id );
|
||||
if ( $this->member and !$item->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/B', 404 );
|
||||
throw new Exception( 'NO_PERMISSION', '2F294/B', 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', '1F294/5', 404 );
|
||||
throw new Exception( 'INVALID_ID', '1F294/5', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user