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

+18 -13
View File
@@ -10,25 +10,29 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\BlogType;
use IPS\blog\Blog as BlogObject;
use OutOfRangeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Blog query for GraphQL API
*/
class _Blog
class Blog
{
/*
* @brief Query description
*/
public static $description = "Returns a Blog";
public static string $description = "Returns a Blog";
/*
* Query arguments
@@ -43,7 +47,7 @@ class _Blog
/**
* Return the query return type
*/
public function type()
public function type(): BlogType
{
return \IPS\blog\api\GraphQL\TypeRegistry::blog();
}
@@ -51,18 +55,19 @@ class _Blog
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Blog
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return BlogObject
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, array $info): BlogObject
{
$blog = \IPS\blog\Blog::load( $args['id'] );
$blog = BlogObject::load( $args[ 'id'] );
if( !$blog->can( 'view', $context['member'] ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
return $blog;
}
+15 -12
View File
@@ -10,25 +10,27 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ListOfType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\Blog;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Blogs query for GraphQL API
*/
class _Blogs
class Blogs
{
/*
* @brief Query description
*/
public static $description = "Returns a list of blogs";
public static string $description = "Returns a list of blogs";
/*
* Query arguments
@@ -43,7 +45,7 @@ class _Blogs
/**
* Return the query return type
*/
public function type()
public function type(): ListOfType
{
return TypeRegistry::listOf( \IPS\blog\api\GraphQL\TypeRegistry::blog() );
}
@@ -51,14 +53,15 @@ class _Blogs
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return array
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, array $info): array
{
\IPS\blog\Blog::loadIntoMemory('view', $context['member']);
return \IPS\blog\Blog::roots();
Blog::loadIntoMemory('view', $context['member']);
return Blog::roots();
}
}
@@ -10,25 +10,35 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use Exception;
use GraphQL\Type\Definition\ListOfType;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\EntryType;
use IPS\blog\Blog;
use IPS\blog\Entry;
use IPS\Db;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use function count;
use function defined;
use function is_array;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Topics query for GraphQL API
*/
class _Entries
class Entries
{
/*
* @brief Query description
*/
public static $description = "Returns a list of blog entries";
public static string $description = "Returns a list of blog entries";
/*
* Query arguments
@@ -49,7 +59,7 @@ class _Entries
'type' => TypeRegistry::eNum([
'name' => 'blog_order_by',
'description' => 'Fields on which event can be sorted',
'values' => \IPS\blog\api\GraphQL\Types\EntryType::getOrderByOptions()
'values' => EntryType::getOrderByOptions()
]),
'defaultValue' => NULL // will use default sort option
],
@@ -71,7 +81,7 @@ class _Entries
/**
* Return the query return type
*/
public function type()
public function type(): ListOfType
{
return TypeRegistry::listOf( \IPS\blog\api\GraphQL\TypeRegistry::entry() );
}
@@ -79,29 +89,30 @@ class _Entries
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Entry
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return ActiveRecordIterator
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, array $info): ActiveRecordIterator
{
\IPS\blog\Blog::loadIntoMemory('view', \IPS\Member::loggedIn() );
Blog::loadIntoMemory('view', Member::loggedIn() );
$blogIds = [];
/* Are we filtering by blogs? */
if( isset( $args['blogs'] ) && \count( $args['blogs'] ) )
if( isset( $args['blogs'] ) && count( $args['blogs'] ) )
{
foreach( $args['blogs'] as $id )
{
$blog = \IPS\blog\Blog::loadAndCheckPerms( $id );
$blog = Blog::loadAndCheckPerms( $id );
$blogIds[] = $blog->id;
}
if( \count( $blogIds ) )
if( count( $blogIds ) )
{
$where['container'][] = array( \IPS\Db::i()->in( 'blog_blogs.blog_id', array_filter( $blogIds ) ) );
$where['container'][] = array( Db::i()->in( 'blog_blogs.blog_id', array_filter( $blogIds ) ) );
}
}
@@ -114,30 +125,30 @@ class _Entries
}
else
{
$orderBy = \IPS\blog\Entry::$databaseColumnMap[ $args['orderBy'] ];
$orderBy = Entry::$databaseColumnMap[ $args['orderBy'] ];
}
if( $args['orderBy'] === 'last_comment' )
{
$orderBy = \is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
$orderBy = is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
}
}
catch (\Exception $e)
catch (Exception)
{
$orderBy = 'last_post';
}
$sortBy = \IPS\blog\Entry::$databaseTable . '.' . \IPS\blog\Entry::$databasePrefix . "{$orderBy} {$args['orderDir']}";
$sortBy = Entry::$databaseTable . '.' . Entry::$databasePrefix . "{$orderBy} {$args['orderDir']}";
$offset = max( $args['offset'], 0 );
$limit = min( $args['limit'], 50 );
/* Figure out pinned status */
if ( $args['honorPinned'] )
{
$column = \IPS\blog\Entry::$databaseTable . '.' . \IPS\blog\Entry::$databasePrefix . \IPS\blog\Entry::$databaseColumnMap['pinned'];
$column = Entry::$databaseTable . '.' . Entry::$databasePrefix . Entry::$databaseColumnMap['pinned'];
$sortBy = "{$column} DESC, {$sortBy}";
}
return \IPS\blog\Entry::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ), 'read' );
return Entry::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ) );
}
}
+22 -17
View File
@@ -10,25 +10,29 @@
*/
namespace IPS\blog\api\GraphQL\Queries;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\EntryType;
use IPS\blog\Entry as EntryClass;
use OutOfRangeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Entry query for GraphQL API
*/
class _Entry
class Entry
{
/*
* @brief Query description
*/
public static $description = "Returns a Blog Entry";
public static string $description = "Returns a Blog Entry";
/*
* Query arguments
@@ -43,7 +47,7 @@ class _Entry
/**
* Return the query return type
*/
public function type()
public function type(): EntryType
{
return \IPS\blog\api\GraphQL\TypeRegistry::entry();
}
@@ -51,25 +55,26 @@ class _Entry
/**
* Resolves this query
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\blog\Entry
*/
public function resolve($val, $args, $context, $info)
{
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param array $info
* @return EntryClass
*/
public function resolve( mixed $val, array $args, array $context, array $info): EntryClass
{
try
{
$entry = \IPS\blog\Entry::loadAndCheckPerms( $args['id'] );
$entry = EntryClass::loadAndCheckPerms( $args['id'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '2B300/A_graphql', 400 );
throw new SafeException( 'NO_TOPIC', '2B300/A_graphql', 400 );
}
if( !$entry->can('read') )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2B300/9_graphql', 403 );
throw new SafeException( 'NO_PERMISSION', '2B300/9_graphql', 403 );
}
return $entry;