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,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 ) );
}
}