Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -25,10 +25,12 @@ class _CommentController extends \IPS\Api\Controller
|
||||
/**
|
||||
* List
|
||||
*
|
||||
* @param array $where Extra WHERE clause
|
||||
* @param array $where Extra WHERE clause
|
||||
* @param string $containerParam The parameter which includes the container values
|
||||
* @param bool $byPassPerms If permissions should be ignored
|
||||
* @return \IPS\Api\PaginatedResponse
|
||||
*/
|
||||
protected function _list( $where = array(), $containerParam = 'categories' )
|
||||
protected function _list( $where = array(), $containerParam = 'categories', $byPassPerms=FALSE )
|
||||
{
|
||||
$class = $this->class;
|
||||
$itemClass = $class::$itemClass;
|
||||
@@ -139,13 +141,27 @@ class _CommentController extends \IPS\Api\Controller
|
||||
}
|
||||
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
|
||||
|
||||
/* Get results */
|
||||
if ( $this->member and !$byPassPerms )
|
||||
{
|
||||
$query = $class::getItemsWithPermission( $where, "{$sortBy} {$sortDir}", NULL, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, $this->member )->getInnerIterator();
|
||||
$count = $class::getItemsWithPermission( $where, "{$sortBy} {$sortDir}", NULL, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, $this->member, FALSE, FALSE, FALSE, TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = \IPS\Db::i()->select( '*', $class::$databaseTable, $where, "{$sortBy} {$sortDir}" )->join( $itemClass::$databaseTable, $itemClass::$databasePrefix . $itemClass::$databaseColumnId . '=' . $class::$databasePrefix . $class::$databaseColumnMap['item'] );
|
||||
$count = \IPS\Db::i()->select( 'COUNT(*)', $class::$databaseTable, $where )->join( $itemClass::$databaseTable, $itemClass::$databasePrefix . $itemClass::$databaseColumnId . '=' . $class::$databasePrefix . $class::$databaseColumnMap['item'] )->first();
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return new \IPS\Api\PaginatedResponse(
|
||||
200,
|
||||
\IPS\Db::i()->select( '*', $class::$databaseTable, $where, "{$sortBy} {$sortDir}" )->join( $itemClass::$databaseTable, $itemClass::$databasePrefix . $itemClass::$databaseColumnId . '=' . $class::$databasePrefix . $class::$databaseColumnMap['item'] ),
|
||||
$query,
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
$class,
|
||||
\IPS\Db::i()->select( 'COUNT(*)', $class::$databaseTable, $where )->join( $itemClass::$databaseTable, $itemClass::$databasePrefix . $itemClass::$databaseColumnId . '=' . $class::$databasePrefix . $class::$databaseColumnMap['item'] )->first()
|
||||
$count,
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,7 +175,7 @@ class _CommentController extends \IPS\Api\Controller
|
||||
*/
|
||||
protected function _create( \IPS\Content\Item $item, \IPS\Member $author, $contentParam='content' )
|
||||
{
|
||||
return new \IPS\Api\Response( 201, $this->_createComment( $item, $author, $contentParam )->apiOutput() );
|
||||
return new \IPS\Api\Response( 201, $this->_createComment( $item, $author, $contentParam )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,17 +189,31 @@ class _CommentController extends \IPS\Api\Controller
|
||||
protected function _createComment( \IPS\Content\Item $item, \IPS\Member $author, $contentParam='content' )
|
||||
{
|
||||
/* Work out the date */
|
||||
$date = \IPS\Request::i()->date ? new \IPS\DateTime( \IPS\Request::i()->date ) : \IPS\DateTime::create();
|
||||
$date = ( !$this->member and \IPS\Request::i()->date ) ? new \IPS\DateTime( \IPS\Request::i()->date ) : \IPS\DateTime::create();
|
||||
|
||||
/* Is it hidden? */
|
||||
$hidden = NULL;
|
||||
if ( isset( \IPS\Request::i()->hidden ) and !$this->member )
|
||||
{
|
||||
$hidden = \IPS\Request::i()->hidden;
|
||||
}
|
||||
|
||||
/* Parse */
|
||||
$content = \IPS\Request::i()->$contentParam;
|
||||
if ( $this->member )
|
||||
{
|
||||
$content = \IPS\Text\Parser::parseStatic( $content, TRUE, NULL, $this->member, $item::$application . '_' . mb_ucfirst( $item::$module ) );
|
||||
}
|
||||
|
||||
/* Create post */
|
||||
$class = $this->class;
|
||||
if ( in_array( 'IPS\Content\Review', class_parents( $class ) ) )
|
||||
{
|
||||
$comment = $class::create( $item, \IPS\Request::i()->$contentParam, FALSE, intval( \IPS\Request::i()->rating ), $author->member_id ? NULL : $author->real_name, $author, $date, \IPS\Request::i()->ip_address ?: \IPS\Request::i()->ipAddress(), isset( \IPS\Request::i()->hidden ) ? \IPS\Request::i()->hidden : NULL );
|
||||
$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()->ipAddress(), $hidden );
|
||||
}
|
||||
else
|
||||
{
|
||||
$comment = $class::create( $item, \IPS\Request::i()->$contentParam, FALSE, $author->member_id ? NULL : $author->real_name, NULL, $author, $date, \IPS\Request::i()->ip_address ?: \IPS\Request::i()->ipAddress(), isset( \IPS\Request::i()->hidden ) ? \IPS\Request::i()->hidden : NULL );
|
||||
$comment = $class::create( $item, $content, FALSE, $author->member_id ? NULL : $author->real_name, NULL, $author, $date, ( !$this->member and \IPS\Request::i()->ip_address ) ?: \IPS\Request::i()->ipAddress(), $hidden );
|
||||
}
|
||||
|
||||
/* Index */
|
||||
@@ -206,6 +236,12 @@ class _CommentController extends \IPS\Api\Controller
|
||||
\IPS\Content\Search\Index::i()->index( $comment );
|
||||
}
|
||||
|
||||
/* Hide */
|
||||
if ( isset( \IPS\Request::i()->hidden ) and $this->member and \IPS\Request::i()->hidden and $comment->canHide( $this->member ) )
|
||||
{
|
||||
$comment->hide( $this->member );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $comment;
|
||||
}
|
||||
@@ -221,7 +257,7 @@ class _CommentController extends \IPS\Api\Controller
|
||||
protected function _edit( $comment, $contentParam='content' )
|
||||
{
|
||||
/* Hidden */
|
||||
if ( isset( \IPS\Request::i()->hidden ) )
|
||||
if ( !$this->member and isset( \IPS\Request::i()->hidden ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->hidden )
|
||||
{
|
||||
@@ -234,7 +270,7 @@ class _CommentController extends \IPS\Api\Controller
|
||||
}
|
||||
|
||||
/* Change author */
|
||||
if ( isset( \IPS\Request::i()->author ) )
|
||||
if ( !$this->member and isset( \IPS\Request::i()->author ) )
|
||||
{
|
||||
$authorIdColumn = $comment::$databaseColumnMap['author'];
|
||||
$authorNameColumn = $comment::$databaseColumnMap['author_name'];
|
||||
@@ -269,7 +305,14 @@ class _CommentController extends \IPS\Api\Controller
|
||||
if ( isset( \IPS\Request::i()->$contentParam ) )
|
||||
{
|
||||
$contentColumn = $comment::$databaseColumnMap['content'];
|
||||
$comment->$contentColumn = \IPS\Request::i()->$contentParam;
|
||||
|
||||
$content = \IPS\Request::i()->$contentParam;
|
||||
if ( $this->member )
|
||||
{
|
||||
$item = $comment->item();
|
||||
$content = \IPS\Text\Parser::parseStatic( $content, TRUE, NULL, $this->member, $item::$application . '_' . mb_ucfirst( $item::$module ) );
|
||||
}
|
||||
$comment->$contentColumn =$content;
|
||||
}
|
||||
|
||||
/* Rating */
|
||||
@@ -295,7 +338,7 @@ class _CommentController extends \IPS\Api\Controller
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return new \IPS\Api\Response( 200, $comment->apiOutput() );
|
||||
return new \IPS\Api\Response( 200, $comment->apiOutput( $this->member ) );
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user