Version 5.0.0 beta 1

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

No files matched your search

@@ -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' );
}
}