Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Base mutator class for comments
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 21 Jun 2018
|
||||
*/
|
||||
|
||||
namespace IPS\Content\Api\GraphQL;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base mutator class for comments
|
||||
*/
|
||||
abstract class _CommentMutator extends ContentMutator
|
||||
{
|
||||
|
||||
/**
|
||||
* Report comment
|
||||
*
|
||||
*/
|
||||
protected function _revokeCommentReport( array $args, \IPS\Content\Comment $comment )
|
||||
{
|
||||
try
|
||||
{
|
||||
$report = \IPS\Db::i()->select( '*', 'core_rc_reports', array( 'id=? AND report_by=? AND date_reported > ?', $args['reportID'], \IPS\Member::loggedIn()->member_id, time() - ( \IPS\Settings::i()->automoderation_report_again_mins * 60 ) ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_REPORT', '1F295/1', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$index = \IPS\core\Reports\Report::load( $report['rid'] );
|
||||
}
|
||||
catch( \OutofRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_REPORT', '1F295/1', 403 );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_rc_reports', array( 'id=?', $args['reportID'] ) );
|
||||
|
||||
/* Recalculate, we may have dropped below the threshold needed to hide a thing */
|
||||
$index->runAutomaticModeration();
|
||||
|
||||
$comment->alreadyReported = NULL;
|
||||
$comment->reportData = array();
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report comment
|
||||
*
|
||||
*/
|
||||
protected function _reportComment( array $args, \IPS\Content\Comment $comment )
|
||||
{
|
||||
$class = $this->class;
|
||||
$canReport = $comment->canReport();
|
||||
|
||||
if ( $canReport !== TRUE AND !( $canReport == 'report_err_already_reported' AND \IPS\Settings::i()->automoderation_enabled ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANNOT_REPORT', '1F295/1', 403 );
|
||||
}
|
||||
|
||||
$itemIdColumn = $class::$databaseColumnId;
|
||||
$idColumn = $comment::$databaseColumnId;
|
||||
|
||||
if ( \IPS\Member::loggedIn()->member_id and \IPS\Settings::i()->automoderation_enabled )
|
||||
{
|
||||
/* Has this member already reported this in the past 24 hours */
|
||||
try {
|
||||
$index = \IPS\core\Reports\Report::loadByClassAndId( \get_class( $comment ), $comment->$idColumn );
|
||||
$report = \IPS\Db::i()->select( '*', 'core_rc_reports', array( 'rid=? and report_by=? and date_reported > ?', $index->id, \IPS\Member::loggedIn()->member_id, time() - ( \IPS\Settings::i()->automoderation_report_again_mins * 60 ) ) );
|
||||
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'ALREADY_REPORTED', '1F295/1', 403 );
|
||||
}
|
||||
catch( \Exception $e ) {
|
||||
if( $e instanceof \IPS\Api\GraphQL\SafeException ){
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
if( !\in_array( $args['reason'], array_keys( \IPS\core\Reports\Types::roots() ) ) && $args['reason'] !== 0 )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_REASON', '1F295/1', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
if( !\IPS\Settings::i()->automoderation_enabled )
|
||||
{
|
||||
$args['reason'] = 0;
|
||||
}
|
||||
|
||||
$args['additionalInfo'] = "<p>" . $args['additionalInfo'] . "</p>";
|
||||
|
||||
try
|
||||
{
|
||||
$comment->report( $args['additionalInfo'], $args['reason'] );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'REPORT_FAILED', '1F295/1', 403 );
|
||||
}
|
||||
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comment reactions
|
||||
*
|
||||
* @param int $reactionID ID of reaction to add
|
||||
* @param \IPS\Content\Comment $comment The comment to add a reaction on
|
||||
* @return void
|
||||
*/
|
||||
protected function _reactComment( $reactionID, \IPS\Content\Comment $comment )
|
||||
{
|
||||
try
|
||||
{
|
||||
$reaction = \IPS\Content\Reaction::load( $reactionID );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_REACTION', '1F295/1', 403 );
|
||||
}
|
||||
|
||||
$comment->react( $reaction );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove comment reaction
|
||||
*
|
||||
* @param \IPS\Content\Comment $comment The comment to remove the reaction on
|
||||
* @return void
|
||||
*/
|
||||
protected function _unreactComment( \IPS\Content\Comment $comment )
|
||||
{
|
||||
try {
|
||||
$comment->removeReaction();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_REACTIONS', '1F295/1', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @param array $commentData Array of data used to generate comment
|
||||
* @param \IPS\Content\Item $item Content Item
|
||||
* @param string $postKey Post key
|
||||
* @return \IPS\Content\Comment
|
||||
*/
|
||||
protected function _createComment( array $commentData, \IPS\Content\Item $item, string $postKey = NULL, $replyTo = NULL )
|
||||
{
|
||||
/* Work out the date */
|
||||
$date = \IPS\DateTime::create();
|
||||
$hidden = false;
|
||||
$quoteHtml = '';
|
||||
|
||||
if( $replyTo !== NULL && $replyTo instanceof \IPS\Content\Comment ){
|
||||
try {
|
||||
$idField = $replyTo::$databaseColumnId;
|
||||
$app = $replyTo::$application;
|
||||
$replyToItem = $replyTo->item();
|
||||
$contentType = $replyToItem::$module;
|
||||
$itemClassSafe = str_replace( '\\', '_', mb_substr( $replyTo::$itemClass, 4 ) );
|
||||
$citationLang = \IPS\Member::loggedIn()->language()->get('_date_just_now_c') . ', ' . $replyTo->mapped('author_name');
|
||||
|
||||
$quoteHtml = <<<HTML
|
||||
<blockquote class="ipsQuote" data-ipsquote="" data-ipsquote-contentapp="{$app}" data-ipsquote-contentclass="{$itemClassSafe}" data-ipsquote-contentcommentid="{$replyTo->mapped('id')}" data-ipsquote-contentid="{$replyTo->item()->mapped('id')}" data-ipsquote-contenttype="{$contentType}" data-ipsquote-timestamp="{$replyTo->mapped('date')}" data-ipsquote-userid="{$replyTo->author()->member_id}" data-ipsquote-username="{$replyTo->mapped('author_name')}">
|
||||
<div class="ipsQuote_citation">
|
||||
{$citationLang}
|
||||
</div>
|
||||
<div class='ipsQuote_contents'>{$replyTo->mapped('content')}</div>
|
||||
</blockquote>
|
||||
HTML;
|
||||
} catch ( \Exception $err ) {
|
||||
// If something goes wrong here, it isn't a big deal - just continue without the quote
|
||||
}
|
||||
}
|
||||
|
||||
/* Add attachments */
|
||||
$attachmentIdsToClaim = array();
|
||||
if ( $postKey )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->_addAttachmentsToContent( $postKey, $commentData['content'] );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'ATTACHMENTS_TOO_LARGE', '2S400/2', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse */
|
||||
$content = $quoteHtml . \IPS\Text\Parser::parseStatic( $commentData['content'], TRUE, md5( $postKey . ':' ), \IPS\Member::loggedIn(), $item::$application . '_' . mb_ucfirst( $item::$module ) );
|
||||
|
||||
/* Create post */
|
||||
$class = $this->class;
|
||||
/*if ( \in_array( 'IPS\Content\Review', class_parents( $class ) ) )
|
||||
{
|
||||
$comment = $class::create( $item, $content, FALSE, \intval( \IPS\Request::i()->rating ), $author->member_id ? NULL : $author->real_name, $author, $date, ( !$this->member and \IPS\Request::i()->ip_address ) ? \IPS\Request::i()->ip_address : \IPS\Request::i()->ipAddress(), $hidden );
|
||||
}
|
||||
else
|
||||
{*/
|
||||
$comment = $class::create( $item, $content, FALSE, \IPS\Member::loggedIn()->member_id ? NULL : \IPS\Member::loggedIn()->real_name, NULL, \IPS\Member::loggedIn(), $date, \IPS\Request::i()->ipAddress() );
|
||||
/*}*/
|
||||
$itemIdColumn = $item::$databaseColumnId;
|
||||
$commentIdColumn = $comment::$databaseColumnId;
|
||||
\IPS\File::claimAttachments( "{$postKey}:", $item->$itemIdColumn, $comment->$commentIdColumn );
|
||||
|
||||
/* Index */
|
||||
if ( $item instanceof \IPS\Content\Searchable )
|
||||
{
|
||||
if ( $item::$firstCommentRequired and !$comment->isFirst() )
|
||||
{
|
||||
if ( \in_array( 'IPS\Content\Searchable', class_implements( $class ) ) )
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( $item->firstComment() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( $item );
|
||||
}
|
||||
}
|
||||
if ( $comment instanceof \IPS\Content\Searchable )
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( $comment );
|
||||
}
|
||||
|
||||
/* Hide */
|
||||
if ( isset( $commentData['hidden'] ) and \IPS\Member::loggedIn()->member_id and $comment->canHide() )
|
||||
{
|
||||
$comment->hide( \IPS\Member::loggedIn() );
|
||||
}
|
||||
|
||||
/* Mark it as read */
|
||||
if( $item instanceof \IPS\Content\ReadMarkers )
|
||||
{
|
||||
$item->markRead();
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $comment;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Base class for Content Comments
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 29 Aug 2018
|
||||
*/
|
||||
|
||||
namespace IPS\Content\Api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base mutator class for Content Comments
|
||||
*/
|
||||
class _CommentType extends ObjectType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $commentClass = '\IPS\Content\Comment';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'core_Comment';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A generic content comment item';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'name' => static::$typeName,
|
||||
'description' => static::$typeDescription,
|
||||
'fields' => function () {
|
||||
return $this->fields();
|
||||
}
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields that this type supports
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
{
|
||||
return array(
|
||||
'id' => [
|
||||
'type' => TypeRegistry::id(),
|
||||
'resolve' => function ($comment) {
|
||||
$idColumn = $comment::$databaseColumnId;
|
||||
return $comment->$idColumn;
|
||||
}
|
||||
],
|
||||
'url' => [
|
||||
'type' => TypeRegistry::url(),
|
||||
'resolve' => function ($comment) {
|
||||
$idColumn = $comment::$databaseColumnId;
|
||||
return $comment->item()->url()->setQueryString( array( 'do' => 'findComment', 'comment' => $comment->$idColumn ) );
|
||||
}
|
||||
],
|
||||
'timestamp' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->mapped('date');
|
||||
}
|
||||
],
|
||||
'author' => [
|
||||
'type' => \IPS\core\api\GraphQL\TypeRegistry::member(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->author();
|
||||
}
|
||||
],
|
||||
'item' => [
|
||||
'type' => \IPS\Content\Api\GraphQL\TypeRegistry::item(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->item();
|
||||
}
|
||||
],
|
||||
'reputation' => [
|
||||
'type' => TypeRegistry::reputation(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment;
|
||||
}
|
||||
],
|
||||
'content' => [
|
||||
'type' => TypeRegistry::richText(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->content();
|
||||
}
|
||||
],
|
||||
'isFirstPost' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($comment) {
|
||||
$idColumn = $comment::$databaseColumnId;
|
||||
return $comment->item()->topic_firstpost == $comment->$idColumn;
|
||||
}
|
||||
],
|
||||
'isIgnored' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->isIgnored();
|
||||
}
|
||||
],
|
||||
'isFeatured' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->isFeatured();
|
||||
}
|
||||
],
|
||||
'hiddenStatus' => [
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => static::$typeName . '_hiddenStatus',
|
||||
'values' => ['HIDDEN', 'PENDING', 'DELETED']
|
||||
]),
|
||||
'resolve' => function ($comment) {
|
||||
switch( $comment->hidden() ){
|
||||
case -2:
|
||||
return 'DELETED';
|
||||
case -1:
|
||||
return 'HIDDEN';
|
||||
case 1:
|
||||
return 'PENDING';
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
],
|
||||
'articleLang' => [
|
||||
'type' => new ObjectType([
|
||||
'name' => static::$typeName . '_articleLang',
|
||||
'fields' => [
|
||||
'indefinite' => TypeRegistry::string(),
|
||||
'definite' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'args' => [
|
||||
'uppercase' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'defaultValue' => FALSE
|
||||
],
|
||||
'withItem' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'defaultValue' => TRUE
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
'resolveField' => function ($item, $args, $context, $info) {
|
||||
$className = \get_class( $item );
|
||||
|
||||
switch( $info->fieldName )
|
||||
{
|
||||
case 'indefinite':
|
||||
return $className::_indefiniteArticle( NULL );
|
||||
break;
|
||||
case 'definite':
|
||||
if( $args['withItem'] === FALSE )
|
||||
{
|
||||
// Normal defart strings are "post in a topic". This option allows us to return "post" instead.
|
||||
// However for now it's something specific to the graphql api
|
||||
return static::definiteArticleNoItem($item, $args['uppercase'] ? array( 'ucfirst' => TRUE ) : array() );
|
||||
}
|
||||
|
||||
// Return normal definite article string handled by \IPS\Content
|
||||
return $className::_definiteArticle( NULL, NULL, $args['uppercase'] ? array( 'ucfirst' => TRUE ) : array() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
]),
|
||||
'resolve' => function ($item) {
|
||||
return $item;
|
||||
}
|
||||
],
|
||||
'commentPermissions' => [
|
||||
'type' => new ObjectType([
|
||||
'name' => static::$typeName . '_commentPermissions',
|
||||
'fields' => static::getCommentPermissionFields()
|
||||
]),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment;
|
||||
}
|
||||
],
|
||||
'reportStatus' => [
|
||||
'type' => \IPS\core\api\GraphQL\TypeRegistry::report(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment;
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field config for the comment permissions query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCommentPermissionFields()
|
||||
{
|
||||
return array(
|
||||
'canShare' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Can the user share this item?',
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->canShare( \IPS\Member::loggedIn() );
|
||||
}
|
||||
],
|
||||
'canReport' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Can the user report this item?',
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->canReport( \IPS\Member::loggedIn() ) === TRUE;
|
||||
}
|
||||
],
|
||||
'canReportOrRevoke' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Can the user report (or revoke a report) on this comment?',
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->canReportOrRevoke( \IPS\Member::loggedIn() ) === TRUE;
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the arguments that will be passed into the item type's schema
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function args()
|
||||
{
|
||||
return array(
|
||||
'offsetPosition' => [
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => static::$typeName . '_offset_position',
|
||||
'description' => 'Provides an easy way to set the offset to a specific relevant position. If ID, the findComment arg is required.',
|
||||
'values' => [ 'FIRST', 'UNREAD', 'LAST', 'ID' ]
|
||||
]),
|
||||
'defaultValue' => 'FIRST'
|
||||
],
|
||||
'offsetAdjust' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'description' => 'Provides the offset to fetch. If offsetPosition is any value other than `CUSTOM`, then this arg adjusts the offset returned by offsetPosition.',
|
||||
'defaultValue' => 0
|
||||
],
|
||||
'findComment' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'description' => 'Sets offset to the position of the comment ID provided.',
|
||||
],
|
||||
'limit' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'defaultValue' => 25
|
||||
],
|
||||
'orderBy' => [
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => static::$typeName . '_order_by',
|
||||
'description' => 'Fields on which comments can be sorted',
|
||||
'values' => [
|
||||
'DATE' => 'date'
|
||||
]
|
||||
]),
|
||||
'defaultValue' => 'DATE'
|
||||
],
|
||||
'orderDir' => [
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => static::$typeName . '_order_dir',
|
||||
'description' => 'Directions in which topics can be sorted',
|
||||
'values' => [ 'ASC', 'DESC' ]
|
||||
]),
|
||||
'defaultValue' => 'ASC'
|
||||
],
|
||||
'includeHidden' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'defaultValue' => NULL,
|
||||
'description' => 'Whether to include hidden comments, if the viewer has permission to see them'
|
||||
],
|
||||
'includeDeleted' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'defaultValue' => NULL,
|
||||
'description' => 'Whether to include deleted comments, if the viewer has permission to see them'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item type that goes with this item type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public static function getItemType()
|
||||
{
|
||||
return \IPS\Content\Api\GraphQL\TypeRegistry::item();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the definite article, but without the item type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function definiteArticleNoItem($post, $options = array())
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( '__defart_comment', FALSE );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Base mutator class for content
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 23 May 2019
|
||||
*/
|
||||
|
||||
namespace IPS\Content\Api\GraphQL;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base mutator class for comments
|
||||
*/
|
||||
abstract class _ContentMutator
|
||||
{
|
||||
/**
|
||||
* Add attachments to content
|
||||
*
|
||||
* @param string $postKey Post key
|
||||
* @param string $content Post content
|
||||
* @return void
|
||||
* @throws \DomainException Size is too large
|
||||
*/
|
||||
protected function _addAttachmentsToContent( $postKey, &$content )
|
||||
{
|
||||
$maxTotalSize = \IPS\Helpers\Form\Editor::maxTotalAttachmentSize( \IPS\Member::loggedIn(), 0 ); // @todo Currently set to 0 because editing is not supported. Once editing is supported by GraphQL, that will need to set the correct value
|
||||
|
||||
$fileAttachments = array();
|
||||
$totalSize = 0;
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_attachments', array( 'attach_post_key=?', $postKey ) ) as $attachment )
|
||||
{
|
||||
if ( $maxTotalSize !== NULL )
|
||||
{
|
||||
$totalSize += $attachment['attach_filesize'];
|
||||
if ( $totalSize > $maxTotalSize )
|
||||
{
|
||||
throw new \DomainException;
|
||||
}
|
||||
}
|
||||
|
||||
$ext = mb_substr( $attachment['attach_file'], mb_strrpos( $attachment['attach_file'], '.' ) + 1 );
|
||||
if ( \in_array( mb_strtolower( $ext ), \IPS\File::$videoExtensions ) )
|
||||
{
|
||||
$content .= \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedVideo( $attachment['attach_location'], \IPS\Http\Url::baseUrl( \IPS\Http\Url::PROTOCOL_RELATIVE ) . "applications/core/interface/file/attachment.php?id=" . $attachment['attach_id'], $attachment['attach_file'], \IPS\File::getMimeType( $attachment['attach_file'] ), $attachment['attach_id'] );
|
||||
}
|
||||
elseif ( $attachment['attach_is_image'] )
|
||||
{
|
||||
if ( $attachment['attach_thumb_location'] )
|
||||
{
|
||||
$ratio = round( ( $attachment['attach_thumb_height'] / $attachment['attach_thumb_width'] ) * 100, 2 );
|
||||
$width = $attachment['attach_thumb_width'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ratio = round( ( $attachment['attach_img_height'] / $attachment['attach_img_width'] ) * 100, 2 );
|
||||
$width = $attachment['attach_img_width'];
|
||||
}
|
||||
|
||||
$content .= str_replace( '<fileStore.core_Attachment>', \IPS\File::getClass('core_Attachment')->baseUrl(), \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedImage( $attachment['attach_location'], $attachment['attach_thumb_location'] ? $attachment['attach_thumb_location'] : $attachment['attach_location'], $attachment['attach_file'], $attachment['attach_id'], $width, $ratio ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$fileAttachments[] = \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedFile( \IPS\Http\Url::baseUrl() . "applications/core/interface/file/attachment.php?id=" . $attachment['attach_id'], $attachment['attach_file'], FALSE, $attachment['attach_ext'], $attachment['attach_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
if( \count( $fileAttachments ) )
|
||||
{
|
||||
$content .= "<p>" . implode( ' ', $fileAttachments ) . "</p>";
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_attachments', array( 'attach_post_key' => '' ), array( 'attach_post_key=?', $postKey ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Base class for Content Items
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 28 Aug 2018
|
||||
*/
|
||||
|
||||
namespace IPS\Content\Api\GraphQL;
|
||||
use GraphQL\Type\Definition\UnionType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base mutator class for Content Items
|
||||
*/
|
||||
class _ContentType extends UnionType
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'name' => 'core_Content',
|
||||
'description' => 'A union type that returns a CommentType, ItemType or @todo ReviewType depending on the object passed to it',
|
||||
'types' => [
|
||||
\IPS\Content\Api\GraphQL\TypeRegistry::comment(),
|
||||
\IPS\Content\Api\GraphQL\TypeRegistry::item()
|
||||
],
|
||||
'resolveType' => function ($content) {
|
||||
if ( $content instanceof \IPS\Content\Comment )
|
||||
{
|
||||
return \IPS\Content\Api\GraphQL\TypeRegistry::comment();
|
||||
}
|
||||
elseif( $content instanceof \IPS\Content\Item )
|
||||
{
|
||||
return \IPS\Content\Api\GraphQL\TypeRegistry::item();
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Base mutator class for Content Items
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 21 Jun 2018
|
||||
*/
|
||||
|
||||
namespace IPS\Content\Api\GraphQL;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base mutator class for Content Items
|
||||
*/
|
||||
abstract class _ItemMutator extends ContentMutator
|
||||
{
|
||||
/**
|
||||
* Mark as read
|
||||
*
|
||||
* @param \IPS\Content\Item $item Item to mark as read
|
||||
* @return void
|
||||
*/
|
||||
protected function _markRead( $item )
|
||||
{
|
||||
$item->markRead();
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @param \IPS\Node\Model $container Container
|
||||
* @param \IPS\Member $author Author
|
||||
* @param string $postKey Post key
|
||||
* @return \IPS\Content\Item
|
||||
*/
|
||||
protected function _create( $itemData, \IPS\Node\Model $container = NULL, string $postKey = NULL )
|
||||
{
|
||||
$class = $this->class;
|
||||
|
||||
/* Work out the date */
|
||||
$date = \IPS\DateTime::create();
|
||||
|
||||
/* Create item */
|
||||
$item = $class::createItem( \IPS\Member::loggedIn(), \IPS\Request::i()->ipAddress(), $date, $container );
|
||||
$this->_createOrUpdate( $item, $itemData, 'add' );
|
||||
$item->save();
|
||||
|
||||
/* Create post */
|
||||
if ( $class::$firstCommentRequired )
|
||||
{
|
||||
$attachmentIdsToClaim = array();
|
||||
if ( $postKey )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->_addAttachmentsToContent( $postKey, $itemData['content'] );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'ATTACHMENTS_TOO_LARGE', '2S401/1', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
$postContents = \IPS\Text\Parser::parseStatic( $itemData['content'], TRUE, md5( $postKey . ':' ), \IPS\Member::loggedIn(), $class::$application . '_' . mb_ucfirst( $class::$module ) );
|
||||
|
||||
$commentClass = $item::$commentClass;
|
||||
$post = $commentClass::create( $item, $postContents, TRUE, \IPS\Member::loggedIn()->member_id ? NULL : \IPS\Member::loggedIn()->real_name, NULL, \IPS\Member::loggedIn(), $date );
|
||||
$itemIdColumn = $item::$databaseColumnId;
|
||||
$postIdColumn = $commentClass::$databaseColumnId;
|
||||
\IPS\File::claimAttachments( "{$postKey}:", $item->$itemIdColumn, $post->$postIdColumn );
|
||||
|
||||
if ( isset( $class::$databaseColumnMap['first_comment_id'] ) )
|
||||
{
|
||||
$firstCommentColumn = $class::$databaseColumnMap['first_comment_id'];
|
||||
$commentIdColumn = $commentClass::$databaseColumnId;
|
||||
$item->$firstCommentColumn = $post->$commentIdColumn;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
||||
/* Index */
|
||||
if ( $item instanceof \IPS\Content\Searchable )
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( $item );
|
||||
}
|
||||
|
||||
/* Mark it as read */
|
||||
if( $item instanceof \IPS\Content\ReadMarkers )
|
||||
{
|
||||
$item->markRead();
|
||||
}
|
||||
|
||||
/* Send notifications */
|
||||
if ( !$item->hidden() )
|
||||
{
|
||||
$item->sendNotifications();
|
||||
}
|
||||
elseif( $item->hidden() !== -1 )
|
||||
{
|
||||
$item->sendUnapprovedNotification();
|
||||
}
|
||||
|
||||
/* Output */
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update item
|
||||
*
|
||||
* @param \IPS\Content\Item $item The item
|
||||
* @param array $itemData Item data
|
||||
* @param string $type add or edit
|
||||
* @param string $postKey Post key
|
||||
* @return \IPS\Content\Item
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\Content\Item $item, array $itemData=array(), $type='add', $postKey = NULL )
|
||||
{
|
||||
$class = $this->class;
|
||||
|
||||
/* Title */
|
||||
if ( isset( $itemData['title'] ) and isset( $item::$databaseColumnMap['title'] ) )
|
||||
{
|
||||
$titleColumn = $item::$databaseColumnMap['title'];
|
||||
$item->$titleColumn = $itemData['title'];
|
||||
}
|
||||
|
||||
/* Tags */
|
||||
if ( ( isset( $itemData['prefix'] ) or isset( $itemData['tags'] ) ) and \in_array( 'IPS\Content\Tags', class_implements( \get_class( $item ) ) ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->member_id && $item::canTag( NULL, $item->containerWrapper() ) )
|
||||
{
|
||||
$source = array();
|
||||
|
||||
if( !\IPS\Settings::i()->tags_open_system )
|
||||
{
|
||||
/* And get the defined tags */
|
||||
if( $class::definedTags( $item->containerWrapper() ) )
|
||||
{
|
||||
$source = array_map( 'trim', array_unique( array_merge( $source, $class::definedTags( $item->containerWrapper() ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Filter our provided tags and exclude any that are invalid */
|
||||
$validTags = array_filter( array_map( 'trim', array_unique( $itemData['tags'] ) ), function($tag) use ($source) {
|
||||
|
||||
if( !\IPS\Settings::i()->tags_open_system && !\in_array($tag, $source) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( \IPS\Settings::i()->tags_len_min && \strlen($tag) < \IPS\Settings::i()->tags_len_min )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( \IPS\Settings::i()->tags_len_max && \strlen($tag) < \IPS\Settings::i()->tags_len_max )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( \strpos( $tag, '#' ) !== FALSE )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
});
|
||||
|
||||
if( \IPS\Settings::i()->tags_min && \count( $validTags ) < \IPS\Settings::i()->tags_min )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'TOO_FEW_TAGS', 'GQL/0011/1', 400 );
|
||||
}
|
||||
|
||||
if( \IPS\Settings::i()->tags_max && \count( $validTags ) > \IPS\Settings::i()->tags_max )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'TOO_MANY_TAGS', 'GQL/0011/2', 400 );
|
||||
}
|
||||
|
||||
/* we need to save the item before we set the tags because setTags requires that the item exists */
|
||||
$idColumn = $item::$databaseColumnId;
|
||||
if ( !$item->$idColumn )
|
||||
{
|
||||
$item->save();
|
||||
}
|
||||
|
||||
$item->setTags( $validTags );
|
||||
}
|
||||
}
|
||||
|
||||
/* Open/closed */
|
||||
if ( isset( $itemData['state']['locked'] ) and \in_array( 'IPS\Content\Lockable', class_implements( \get_class( $item ) ) ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->member_id && ( $itemData['state']['locked'] and $item->canLock() ) or ( !$itemData['state']['locked'] and $item->canUnlock() ) )
|
||||
{
|
||||
if ( isset( $item::$databaseColumnMap['locked'] ) )
|
||||
{
|
||||
$lockedColumn = $item::$databaseColumnMap['locked'];
|
||||
$item->$lockedColumn = \intval( $itemData['state']['locked'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$stateColumn = $item::$databaseColumnMap['status'];
|
||||
$item->$stateColumn = $itemData['state']['locked'] ? 'closed' : 'open';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Hidden */
|
||||
if ( isset( $itemData['state']['hidden'] ) and \in_array( 'IPS\Content\Hideable', class_implements( \get_class( $item ) ) ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->member_id && ( $itemData['state']['hidden'] and $item->canHide() ) or ( !$itemData['state']['hidden'] and $item->canUnhide() ) )
|
||||
{
|
||||
$idColumn = $item::$databaseColumnId;
|
||||
if ( $itemData['state']['hidden'] )
|
||||
{
|
||||
if ( $item->$idColumn )
|
||||
{
|
||||
$item->hide( FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( $item::$databaseColumnMap['hidden'] ) )
|
||||
{
|
||||
$hiddenColumn = $item::$databaseColumnMap['hidden'];
|
||||
$item->$hiddenColumn = $itemData['state']['hidden'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$approvedColumn = $item::$databaseColumnMap['approved'];
|
||||
$item->$approvedColumn = ( $itemData['state']['hidden'] == -1 ) ? -1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $item->$idColumn )
|
||||
{
|
||||
$item->unhide( FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( $item::$databaseColumnMap['hidden'] ) )
|
||||
{
|
||||
$hiddenColumn = $item::$databaseColumnMap['hidden'];
|
||||
$item->$hiddenColumn = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$approvedColumn = $item::$databaseColumnMap['approved'];
|
||||
$item->$approvedColumn = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Pinned */
|
||||
if ( isset( $itemData['state']['pinned'] ) and \in_array( 'IPS\Content\Pinnable', class_implements( \get_class( $item ) ) ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->member_id && ( $itemData['state']['pinned'] and $item->canPin() ) or ( !$itemData['state']['pinned'] and $item->canUnpin() ) )
|
||||
{
|
||||
$pinnedColumn = $item::$databaseColumnMap['pinned'];
|
||||
$item->$pinnedColumn = \intval( $itemData['state']['pinned'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Featured */
|
||||
if ( isset( $itemData['state']['featured'] ) and \in_array( 'IPS\Content\Featurable', class_implements( \get_class( $item ) ) ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->member_id && ( $itemData['state']['featured'] and $item->canFeature() ) or ( !$itemData['state']['featured'] and $item->canUnfeature() ) )
|
||||
{
|
||||
$featuredColumn = $item::$databaseColumnMap['featured'];
|
||||
$item->$featuredColumn = \intval( $itemData['state']['featured'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Update first comment if required, and it's not a new item */
|
||||
$field = isset( $item::$databaseColumnMap['first_comment_id'] ) ? $item::$databaseColumnMap['first_comment_id'] : NULL;
|
||||
$commentClass = $item::$commentClass;
|
||||
$contentField = $commentClass::$databaseColumnMap['content'];
|
||||
if ( $item::$firstCommentRequired AND isset( $item->$field ) AND isset( $itemData[ $contentField ] ) AND $type == 'edit' )
|
||||
{
|
||||
$attachmentIdsToClaim = array();
|
||||
if ( $postKey )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->_addAttachmentsToContent( $postKey, $itemData[ $contentField ] );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'ATTACHMENTS_TOO_LARGE', '2S401/2', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
$content = \IPS\Text\Parser::parseStatic( $itemData[ $contentField ], TRUE, array( $item->_id, $item->$field ), \IPS\Member::loggedIn(), $item::$application . '_' . mb_ucfirst( $item::$module ) );
|
||||
|
||||
try
|
||||
{
|
||||
$comment = $commentClass::load( $item->$field );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_FIRST_POST', '1S377/1', 400 );
|
||||
}
|
||||
|
||||
$comment->$contentField = $content;
|
||||
$comment->save();
|
||||
|
||||
/* Update Search Index of the first item */
|
||||
if ( $item instanceof \IPS\Content\Searchable )
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( $comment );
|
||||
}
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,894 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Base class for Content Items
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 28 Aug 2018
|
||||
*/
|
||||
|
||||
namespace IPS\Content\Api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base mutator class for Content Items
|
||||
*/
|
||||
class _ItemType extends ObjectType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $itemClass = '\IPS\Content\Item';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'core_Item';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A generic content item';
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'name' => static::$typeName,
|
||||
'description' => static::$typeDescription,
|
||||
'fields' => function () {
|
||||
return $this->fields();
|
||||
}
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields that this type supports
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
{
|
||||
return array(
|
||||
'id' => [
|
||||
'type' => TypeRegistry::id(),
|
||||
'resolve' => function ($item) {
|
||||
$idColumn = static::getIdColumn($item);
|
||||
return $item->$idColumn;
|
||||
}
|
||||
],
|
||||
'url' => [
|
||||
'type' => TypeRegistry::url(),
|
||||
'resolve' => function ($item) {
|
||||
return $item->url();
|
||||
}
|
||||
],
|
||||
'title' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($item) {
|
||||
return $item->mapped('title');
|
||||
}
|
||||
],
|
||||
'seoTitle' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($item) {
|
||||
return \IPS\Http\Url\Friendly::seoTitle( $item->mapped('title') );
|
||||
}
|
||||
],
|
||||
'views' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'resolve' => function ($item) {
|
||||
if ( \in_array( 'IPS\Content\Views', class_implements( $item ) ) )
|
||||
{
|
||||
return $item->mapped('views');
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'commentCount' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'args' => [
|
||||
'includeHidden' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => "Should the count include hidden/unapproved comments that the logged in member can see?",
|
||||
'defaultValue' => FALSE
|
||||
]
|
||||
],
|
||||
'resolve' => function ($item, $args) {
|
||||
if( $args['includeHidden'] && method_exists( $item, 'commentCount' ) ){
|
||||
return $item->commentCount();
|
||||
}
|
||||
|
||||
return $item->mapped('num_comments');
|
||||
}
|
||||
],
|
||||
'isLocked' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($item) {
|
||||
if ( \in_array( 'IPS\Content\Lockable', class_implements( $item ) ) )
|
||||
{
|
||||
return (bool) $item->locked();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'isPinned' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($item) {
|
||||
if ( \in_array( 'IPS\Content\Pinnable', class_implements( $item ) ) )
|
||||
{
|
||||
return (bool) $item->mapped('pinned');
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'isFeatured' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($item) {
|
||||
if ( \in_array( 'IPS\Content\Featurable', class_implements( $item ) ) )
|
||||
{
|
||||
return (bool) $item->mapped('featured');
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'hiddenStatus' => [
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => static::$typeName . '_hiddenStatus',
|
||||
'values' => ['HIDDEN', 'PENDING', 'DELETED']
|
||||
]),
|
||||
'resolve' => function ($item) {
|
||||
if ( !\in_array( 'IPS\Content\Hideable', class_implements( $item ) ) )
|
||||
{
|
||||
switch( $item->hidden() ){
|
||||
case -2:
|
||||
return 'DELETED';
|
||||
case -1:
|
||||
return 'HIDDEN';
|
||||
case 1:
|
||||
return 'PENDING';
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
'updated' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($item) {
|
||||
return $item->mapped('updated');
|
||||
}
|
||||
],
|
||||
'started' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($item) {
|
||||
return $item->mapped('date');
|
||||
}
|
||||
],
|
||||
'isUnread' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($item) {
|
||||
if ( \in_array( 'IPS\Content\ReadMarkers', class_implements( $item ) ) )
|
||||
{
|
||||
return $item->unread();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'timeLastRead' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'resolve' => function ($item) {
|
||||
return static::timeLastRead($item);
|
||||
}
|
||||
],
|
||||
'unreadCommentPosition' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'description' => 'Returns the position of the comment that is the first unread in this topic',
|
||||
'resolve' => function ($item) {
|
||||
if ( \in_array( 'IPS\Content\ReadMarkers', class_implements( $item ) ) )
|
||||
{
|
||||
return static::getUnreadPosition($item);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'findCommentPosition' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'args' => [
|
||||
'findComment' => TypeRegistry::int()
|
||||
],
|
||||
'description' => 'Returns the position of the comment provided in the required findComment arg',
|
||||
'resolve' => function ($item, $args) {
|
||||
return static::findCommentPosition($item, $args);
|
||||
}
|
||||
],
|
||||
'follow' => [
|
||||
'type' => TypeRegistry::follow(),
|
||||
'resolve' => function ($item) {
|
||||
if( \in_array( 'IPS\Content\Followable', class_implements( $item ) ) && isset( static::$followData ) && \is_array( static::$followData ) ){
|
||||
$idColumn = static::getIdColumn($item);
|
||||
return array_merge( static::$followData, array(
|
||||
'id' => $item->$idColumn,
|
||||
'item' => $item,
|
||||
'itemClass' => static::$itemClass
|
||||
));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'tags' => [
|
||||
'type' => TypeRegistry::listOf( \IPS\core\api\GraphQL\TypeRegistry::tag() ),
|
||||
'resolve' => function ($item) {
|
||||
if ( \in_array( 'IPS\Content\Tags', class_implements( $item ) ) )
|
||||
{
|
||||
return static::tags($item);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'author' => [
|
||||
'type' => \IPS\core\api\GraphQL\TypeRegistry::member(),
|
||||
'resolve' => function ($item, $args) {
|
||||
return static::author($item, $args);
|
||||
}
|
||||
],
|
||||
'container' => [
|
||||
// @todo return generic node
|
||||
'type' => \IPS\Node\Api\GraphQL\TypeRegistry::node(),
|
||||
'resolve' => function ($item) {
|
||||
return $item->container();
|
||||
}
|
||||
],
|
||||
'content' => [
|
||||
'type' => TypeRegistry::richText(),
|
||||
'resolve' => function ($item) {
|
||||
return $item->content();
|
||||
}
|
||||
],
|
||||
'contentImages' => [
|
||||
'type' => TypeRegistry::listOf( TypeRegistry::string() ),
|
||||
'resolve' => function ($item) {
|
||||
return static::contentImages($item);
|
||||
}
|
||||
],
|
||||
'hasPoll' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($item) {
|
||||
return $item instanceof \IPS\Content\Polls && $item->poll_state;
|
||||
}
|
||||
],
|
||||
'poll' => [
|
||||
'type' => \IPS\core\api\GraphQL\TypeRegistry::poll(),
|
||||
'resolve' => function ($item) {
|
||||
if( $item instanceof \IPS\Content\Polls && $item->poll_state )
|
||||
{
|
||||
return $item->getPoll();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'firstCommentRequired' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'resolve' => function ($item) {
|
||||
return static::$itemClass::$firstCommentRequired;
|
||||
}
|
||||
],
|
||||
'articleLang' => [
|
||||
'type' => new ObjectType([
|
||||
'name' => static::$typeName . '_articleLang',
|
||||
'fields' => [
|
||||
'indefinite' => TypeRegistry::string(),
|
||||
'definite' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'args' => [
|
||||
'uppercase' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'defaultValue' => FALSE
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'resolveField' => function ($item, $args, $context, $info) {
|
||||
$className = \get_class( $item );
|
||||
|
||||
switch( $info->fieldName )
|
||||
{
|
||||
case 'indefinite':
|
||||
return $className::_indefiniteArticle( NULL );
|
||||
break;
|
||||
case 'definite':
|
||||
return $className::_definiteArticle( NULL, NULL, $args['uppercase'] ? array( 'ucfirst' => TRUE ) : array() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
]),
|
||||
'resolve' => function ($item) {
|
||||
return $item;
|
||||
}
|
||||
],
|
||||
'lastCommentAuthor' => [
|
||||
'type' => \IPS\core\api\GraphQL\TypeRegistry::member(),
|
||||
'resolve' => function ($item, $args) {
|
||||
return static::lastCommentAuthor($item, $args);
|
||||
}
|
||||
],
|
||||
'lastCommentDate' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($item, $args) {
|
||||
return static::lastCommentDate($item, $args);
|
||||
}
|
||||
],
|
||||
'comments' => [
|
||||
'type' => TypeRegistry::listOf( static::getCommentType() ),
|
||||
'args' => static::getCommentType()::args(),
|
||||
'resolve' => function ($item, $args, $context) {
|
||||
return static::comments($item, $args);
|
||||
}
|
||||
],
|
||||
'itemPermissions' => [
|
||||
'type' => new ObjectType([
|
||||
'name' => static::$typeName . '_itemPermissions',
|
||||
'fields' => static::getItemPermissionFields()
|
||||
]),
|
||||
'resolve' => function ($item) {
|
||||
return $item;
|
||||
}
|
||||
],
|
||||
'uploadPermissions' => [
|
||||
'type' => \IPS\core\api\GraphQL\TypeRegistry::attachmentPermissions(),
|
||||
'description' => 'Details about what the user can attach when commenting on this item.',
|
||||
'args' => [
|
||||
'postKey' => TypeRegistry::nonNull( TypeRegistry::string() ),
|
||||
],
|
||||
'resolve' => function( $node, $args, $context ) {
|
||||
return array( 'postKey' => $args['postKey'] );
|
||||
}
|
||||
],
|
||||
'reportStatus' => [
|
||||
'type' => \IPS\core\api\GraphQL\TypeRegistry::report(),
|
||||
'resolve' => function ($item) {
|
||||
return $item;
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ID column for the provided item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getIdColumn($item)
|
||||
{
|
||||
$className = \get_class( $item );
|
||||
return $className::$databaseColumnId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the arguments that can be used to filter topics. Passed into NodeType.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function args()
|
||||
{
|
||||
return array(
|
||||
'offset' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'defaultValue' => 0
|
||||
],
|
||||
'limit' => [
|
||||
'type' => TypeRegistry::int(),
|
||||
'defaultValue' => 25
|
||||
],
|
||||
'orderBy' => [
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => static::$typeName . '_order_by',
|
||||
'description' => 'Fields on which items can be sorted',
|
||||
'values' => static::getOrderByOptions()
|
||||
]),
|
||||
'defaultValue' => NULL // will use default sort option
|
||||
],
|
||||
'orderDir' => [
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => static::$typeName . '_order_dir',
|
||||
'description' => 'Directions in which items can be sorted',
|
||||
'values' => [ 'ASC', 'DESC' ]
|
||||
]),
|
||||
'defaultValue' => 'DESC'
|
||||
],
|
||||
'honorPinned' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'defaultValue' => true
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the available sorting options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderByOptions()
|
||||
{
|
||||
return array('title', 'author_name', 'last_comment_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field config for the item permissions query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getItemPermissionFields()
|
||||
{
|
||||
return array(
|
||||
'canComment' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Can the logged in user comment on this item?',
|
||||
'resolve' => function ($item, $args, $context) {
|
||||
return $item->canComment( \IPS\Member::loggedIn(), FALSE );
|
||||
}
|
||||
],
|
||||
'commentInformation' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'description' => 'A message providing some information about the comment form availability',
|
||||
'resolve' => function ($item, $args, $context) {
|
||||
if( $item->canComment( \IPS\Member::loggedIn(), FALSE ) )
|
||||
{
|
||||
if( $item instanceof \IPS\Content\Lockable && $item->locked() )
|
||||
{
|
||||
return 'locked_can_comment';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $item instanceof \IPS\Content\Lockable && $item->locked() )
|
||||
{
|
||||
return 'locked_cannot_comment';
|
||||
}
|
||||
elseif( \IPS\Member::loggedIn()->restrict_post )
|
||||
{
|
||||
return 'restricted_cannot_comment';
|
||||
}
|
||||
elseif( \IPS\Member::loggedIn()->members_bitoptions['unacknowledged_warnings'] )
|
||||
{
|
||||
return 'unacknowledged_warning_cannot_post';
|
||||
}
|
||||
elseif( !\IPS\Member::loggedIn()->checkPostsPerDay() )
|
||||
{
|
||||
return 'member_exceeded_posts_per_day';
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'canCommentIfSignedIn' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Returns boolean indicating whether a guest who signs in would be able to comment on this item. Returns NULL if already signed in.',
|
||||
'resolve' => function ($item, $args, $context) {
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$testUser = new \IPS\Member;
|
||||
$testUser->member_group_id = \IPS\Settings::i()->member_group;
|
||||
|
||||
return $item->canComment( $testUser, FALSE );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
],
|
||||
'canMarkAsRead' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Boolean indicating whether this item supports read markers, and if so, if the user can mark as read',
|
||||
'resolve' => function ($item) {
|
||||
return $item instanceof \IPS\Content\ReadMarkers && \IPS\Member::loggedIn()->member_id;
|
||||
}
|
||||
],
|
||||
'canReport' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Can the user report this item?',
|
||||
'resolve' => function ($item) {
|
||||
return $item->canReport( \IPS\Member::loggedIn() ) === TRUE;
|
||||
}
|
||||
],
|
||||
'canReportOrRevoke' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Can the user report (or revoke a report) on this item?',
|
||||
'resolve' => function ($item) {
|
||||
return $item->canReportOrRevoke( \IPS\Member::loggedIn() ) === TRUE;
|
||||
}
|
||||
],
|
||||
'canShare' => [
|
||||
'type' => TypeRegistry::boolean(),
|
||||
'description' => 'Can this item be shared?',
|
||||
'resolve' => function ($item) {
|
||||
return $item->canShare();
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the comment type that goes with this item type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
protected static function getCommentType()
|
||||
{
|
||||
return \IPS\Content\Api\GraphQL\TypeRegistry::comment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content images for the provided item
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected static function contentImages($item)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( $images = $item->contentImages( 20 ) )
|
||||
{
|
||||
foreach( $images as $image )
|
||||
{
|
||||
foreach( $image as $extension => $file )
|
||||
{
|
||||
$toReturn[] = (string) \IPS\File::get( $extension, $file )->url;
|
||||
}
|
||||
}
|
||||
return $toReturn;
|
||||
}
|
||||
}
|
||||
catch( \BadMethodCallException $e ) { }
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the findCommentPosition field
|
||||
*
|
||||
* @param \IPS\forums\Topic
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return array
|
||||
*/
|
||||
protected static function findCommentPosition($item, $args)
|
||||
{
|
||||
if( $args['findComment'] === NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$comment = static::$itemClass::$commentClass::load( $args['findComment'] );
|
||||
|
||||
// Check this comment belongs to this topic
|
||||
if( $comment->item() !== $item )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return static::findComment($comment, $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the comments field
|
||||
*
|
||||
* @param \IPS\forums\Topic
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return array
|
||||
*/
|
||||
protected static function comments($item, $args)
|
||||
{
|
||||
$offset = 0;
|
||||
$limit = 25;
|
||||
|
||||
/* Figure out where we're starting our offset */
|
||||
switch( $args['offsetPosition'] )
|
||||
{
|
||||
case 'UNREAD':
|
||||
$offset = static::getUnreadPosition($item) + $args['offsetAdjust'];
|
||||
break;
|
||||
case 'LAST':
|
||||
// Since we're zero-indexed, when we're working from the end we need to go one more to get the last item
|
||||
$offset = static::getEndPosition($item) + $args['offsetAdjust'] + 1;
|
||||
break;
|
||||
case 'ID':
|
||||
if( !isset( $args['findComment'] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
$offset = static::getCommentPosition($item, $args['findComment']) + $args['offsetAdjust'];
|
||||
break;
|
||||
case 'FIRST':
|
||||
default:
|
||||
$offset = 0 + $args['offsetAdjust'];
|
||||
}
|
||||
|
||||
/* Ensure offset is never lower than 0 */
|
||||
$offset = max( $offset, 0 );
|
||||
$limit = min( $args['limit'], 50 );
|
||||
|
||||
if( $args['orderBy'] == 'DATE' )
|
||||
{
|
||||
$args['orderBy'] = static::$itemClass::$commentClass::$databaseColumnMap['date'];
|
||||
}
|
||||
|
||||
|
||||
// We can't allow straight boolean TRUE here otherwise members without permission
|
||||
// will see them. Instead, if TRUE is passed as a value in the query, set the value
|
||||
// to NULL which honors permissions.
|
||||
$includeDeleted = $args['includeDeleted'] ? NULL : FALSE;
|
||||
$includeHidden = $args['includeHidden'] ? NULL : FALSE;
|
||||
|
||||
return $item->comments( $limit, $offset, $args['orderBy'], $args['orderDir'], NULL, $includeHidden, NULL, NULL, NULL, $includeDeleted );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of a specific comment
|
||||
*
|
||||
* @param \IPS\Content\Item
|
||||
* @return int
|
||||
*/
|
||||
protected static function getCommentPosition($item, $commentID)
|
||||
{
|
||||
try
|
||||
{
|
||||
$comment = static::$itemClass::$commentClass::load($commentID);
|
||||
return static::findComment($comment, $item);
|
||||
}
|
||||
catch(\Exception $error)
|
||||
{}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the last comment
|
||||
*
|
||||
* @param \IPS\Content\Item
|
||||
* @return int
|
||||
*/
|
||||
protected static function getEndPosition($item)
|
||||
{
|
||||
$comment = $item->comments( 1, NULL, 'date', 'desc' );
|
||||
return static::findComment($comment, $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the first unread comment
|
||||
*
|
||||
* @param \IPS\Content\Item
|
||||
* @return int
|
||||
*/
|
||||
protected static function getUnreadPosition($item)
|
||||
{
|
||||
try
|
||||
{
|
||||
$class = static::$itemClass;
|
||||
$timeLastRead = $item->timeLastRead();
|
||||
|
||||
if ( $timeLastRead instanceof \IPS\DateTime )
|
||||
{
|
||||
$comment = NULL;
|
||||
if( \IPS\DateTime::ts( $item->mapped('date') ) < $timeLastRead )
|
||||
{
|
||||
$comment = $item->comments( 1, NULL, 'date', 'asc', NULL, NULL, $timeLastRead );
|
||||
}
|
||||
|
||||
/* If we don't have any unread comments... */
|
||||
if ( !$comment and $class::$firstCommentRequired )
|
||||
{
|
||||
/* If we haven't read the item at all, go there */
|
||||
if ( $item->unread() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* Otherwise, go to the last comment */
|
||||
else
|
||||
{
|
||||
$comment = $item->comments( 1, NULL, 'date', 'desc' );
|
||||
}
|
||||
}
|
||||
|
||||
if( !$comment ){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $item->unread() )
|
||||
{
|
||||
/* If we do not have a time last read set for this content, fallback to the reset time */
|
||||
$resetTimes = \IPS\Member::loggedIn()->markersResetTimes( $class::$application );
|
||||
|
||||
if ( array_key_exists( $item->container()->_id, $resetTimes ) and $item->mapped('date') < $resetTimes[ $item->container()->_id ] )
|
||||
{
|
||||
$comment = $item->comments( 1, NULL, 'date', 'asc', NULL, NULL, \IPS\DateTime::ts( $resetTimes[ $item->container()->_id ] ) );
|
||||
|
||||
if ( !$comment || $class::$firstCommentRequired and $comment->isFirst() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return static::findComment($comment, $item);
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the position of a comment
|
||||
*
|
||||
* @param \IPS\Content\Comment
|
||||
* @param \IPS\Content\Item
|
||||
* @return int
|
||||
*/
|
||||
protected static function findComment($comment, $item)
|
||||
{
|
||||
try
|
||||
{
|
||||
$commentClass = \get_class( $comment );
|
||||
$idColumn = $commentClass::$databaseColumnId;
|
||||
$itemColumn = $commentClass::$databaseColumnMap['item'];
|
||||
|
||||
/* Work out where the comment is in the item */
|
||||
$directional = ( \in_array( 'IPS\Content\Review', class_parents( $commentClass ) ) ) ? '>=?' : '<=?';
|
||||
$where = array(
|
||||
array( $commentClass::$databasePrefix . $itemColumn . '=?', $comment->$itemColumn ),
|
||||
array( $commentClass::$databasePrefix . $idColumn . $directional, $comment->$idColumn )
|
||||
);
|
||||
|
||||
/* Exclude content pending deletion, as it will not be shown inline */
|
||||
if ( isset( $commentClass::$databaseColumnMap['approved'] ) )
|
||||
{
|
||||
$where[] = array( $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['approved'] . '<>?', -2 );
|
||||
}
|
||||
elseif( isset( $commentClass::$databaseColumnMap['hidden'] ) )
|
||||
{
|
||||
$where[] = array( $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['hidden'] . '<>?', -2 );
|
||||
}
|
||||
|
||||
if ( $commentClass::commentWhere() !== NULL )
|
||||
{
|
||||
$where[] = $commentClass::commentWhere();
|
||||
}
|
||||
if ( $container = $item->containerWrapper() )
|
||||
{
|
||||
if ( $commentClass::modPermission( 'view_hidden', NULL, $container ) === FALSE )
|
||||
{
|
||||
if ( isset( $commentClass::$databaseColumnMap['approved'] ) )
|
||||
{
|
||||
$where[] = array( $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['approved'] . '=?', 1 );
|
||||
}
|
||||
elseif( isset( $commentClass::$databaseColumnMap['hidden'] ) )
|
||||
{
|
||||
$where[] = array( $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['hidden'] . '=?', 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
$commentPosition = \IPS\Db::i()->select( 'COUNT(*) AS position', $commentClass::$databaseTable, $where )->first();
|
||||
|
||||
if( static::$itemClass::$firstCommentRequired ){
|
||||
$commentPosition = $commentPosition - 1;
|
||||
}
|
||||
|
||||
return $commentPosition;
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the tags field
|
||||
*
|
||||
* @param \IPS\Content\Item
|
||||
* @return int
|
||||
*/
|
||||
protected static function timeLastRead($item)
|
||||
{
|
||||
$time = $item->timeLastRead();
|
||||
if( $time instanceof \IPS\DateTime )
|
||||
{
|
||||
return (int) $time->setTimezone( new \DateTimeZone( "UTC" ) )->format('U');
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the tags field
|
||||
*
|
||||
* @param \IPS\Content\Item
|
||||
* @return array
|
||||
*/
|
||||
protected static function tags($item)
|
||||
{
|
||||
$tags = $item->tags();
|
||||
return \is_array( $tags ) ? $tags : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the author field
|
||||
*
|
||||
* @param null
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return \IPS\forums\Forum
|
||||
*/
|
||||
protected static function author($item, $args)
|
||||
{
|
||||
return $item->author();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the last comment author field
|
||||
*
|
||||
* @param \IPS\forums\Topic
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return \IPS\Member
|
||||
*/
|
||||
protected static function lastCommentAuthor($item, $args)
|
||||
{
|
||||
if( $item->mapped('num_comments') )
|
||||
{
|
||||
return $item->lastCommenter();
|
||||
}
|
||||
|
||||
return $item->author();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the last comment date field
|
||||
*
|
||||
* @param \IPS\forums\Topic
|
||||
* @param array Arguments passed to this resolver
|
||||
* @return string
|
||||
*/
|
||||
protected static function lastCommentDate($item, $args)
|
||||
{
|
||||
if( $item->mapped('last_comment') )
|
||||
{
|
||||
return $item->mapped('last_comment');
|
||||
}
|
||||
|
||||
return $item->mapped('date');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Type registry for \IPS\Content types
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @since 29 Aug 2018
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Content\Api\GraphQL;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* \IPS\Content base types
|
||||
*/
|
||||
class _TypeRegistry
|
||||
{
|
||||
protected static $comment;
|
||||
protected static $content;
|
||||
protected static $item;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Defined to suppress static warnings
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CommentType
|
||||
*/
|
||||
public static function comment()
|
||||
{
|
||||
return self::$comment ?: (self::$comment = new \IPS\Content\Api\GraphQL\CommentType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemType
|
||||
*/
|
||||
public static function item()
|
||||
{
|
||||
return self::$item ?: (self::$item = new \IPS\Content\Api\GraphQL\ItemType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ContentType
|
||||
*/
|
||||
public static function content()
|
||||
{
|
||||
return self::$content ?: (self::$content = new \IPS\Content\Api\GraphQL\ContentType());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user