Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,58 +12,86 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Records;
|
||||
use IPS\Content\Anonymous;
|
||||
use IPS\Content\Comment as ContentComment;
|
||||
use IPS\Content\EditHistory;
|
||||
use IPS\Content\Embeddable;
|
||||
use IPS\Content\Filter;
|
||||
use IPS\Content\Hideable;
|
||||
use IPS\Content\Featurable;
|
||||
use IPS\Content\Reactable;
|
||||
use IPS\Content\Reportable;
|
||||
use IPS\Content\Shareable;
|
||||
use IPS\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
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 Model
|
||||
*/
|
||||
class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Shareable, \IPS\Content\Searchable, \IPS\Content\Embeddable, \IPS\Content\Anonymous
|
||||
class Comment extends ContentComment implements Embeddable,
|
||||
Filter
|
||||
{
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable;
|
||||
use Reactable,
|
||||
Reportable,
|
||||
Anonymous,
|
||||
Shareable,
|
||||
EditHistory,
|
||||
Hideable,
|
||||
Featurable;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Item Class
|
||||
*/
|
||||
public static $itemClass = NULL;
|
||||
public static ?string $itemClass = NULL;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'cms_database_comments';
|
||||
public static ?string $databaseTable = 'cms_database_comments';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'comment_';
|
||||
public static string $databasePrefix = 'comment_';
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'cms';
|
||||
public static string $application = 'cms';
|
||||
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'content_comment';
|
||||
public static string $title = 'content_comment';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'item' => 'record_id',
|
||||
'author' => 'user',
|
||||
'author_name' => 'author',
|
||||
@@ -83,35 +111,28 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'comment';
|
||||
public static string $icon = 'comments';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Comment Template
|
||||
*/
|
||||
public static $commentTemplate = array( array( 'display', 'cms', 'database' ), 'commentContainer' );
|
||||
public static array $commentTemplate = array( array( 'display', 'cms', 'database' ), 'commentContainer' );
|
||||
|
||||
/**
|
||||
* @brief Database ID
|
||||
*/
|
||||
public static $customDatabaseId = NULL;
|
||||
|
||||
/**
|
||||
* @brief Store generated search index titles for efficiency
|
||||
*/
|
||||
protected static $searchIndexTitles = array();
|
||||
public static ?int $customDatabaseId = NULL;
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details) - if used will cause multiton store to be skipped and a query always ran
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
* @param int|string|null $id ID
|
||||
* @param string|null $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details) - if used will cause multiton store to be skipped and a query always ran
|
||||
* @return ActiveRecord|Comment
|
||||
* @see Db::build
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
public static function load( int|string|null $id, string $idField=NULL, mixed $extraWhereClause=NULL ): ActiveRecord|static
|
||||
{
|
||||
if ( static::commentWhere() !== NULL )
|
||||
{
|
||||
@@ -131,10 +152,12 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
/**
|
||||
* Post count for member
|
||||
*
|
||||
* @param \IPS\Member $member The memner
|
||||
* @return int
|
||||
* @param Member $member The memner
|
||||
* @param bool $includeNonPostCountIncreasing
|
||||
* @param bool $includeHiddenAndPendingApproval
|
||||
* @return int
|
||||
*/
|
||||
public static function memberPostCount( \IPS\Member $member, bool $includeNonPostCountIncreasing = FALSE, bool $includeHiddenAndPendingApproval = TRUE )
|
||||
public static function memberPostCount( Member $member, bool $includeNonPostCountIncreasing = FALSE, bool $includeHiddenAndPendingApproval = TRUE ): int
|
||||
{
|
||||
$where = [];
|
||||
$where[] = [ 'comment_database_id=?', static::$customDatabaseId ];
|
||||
@@ -145,7 +168,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
$where[] = [ 'comment_approved=1' ];
|
||||
}
|
||||
|
||||
return \IPS\Db::i()->select( 'COUNT(*)', static::$databaseTable, $where )->first();
|
||||
return Db::i()->select( 'COUNT(*)', static::$databaseTable, $where )->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +177,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
* @param int $id Content item to delete from
|
||||
* @return array
|
||||
*/
|
||||
public static function deleteWhereSql( $id )
|
||||
public static function deleteWhereSql( int $id ) : array
|
||||
{
|
||||
return array( array( static::$databasePrefix . static::$databaseColumnMap['item'] . '=?', $id ), array( static::$databasePrefix . 'database_id=?', static::$customDatabaseId ) );
|
||||
}
|
||||
@@ -164,73 +187,36 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function findByIPWhere()
|
||||
public static function findByIPWhere() : string
|
||||
{
|
||||
return " AND comment_database_id=" . static::$customDatabaseId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get items with permisison check
|
||||
*
|
||||
* @param array $where Where clause
|
||||
* @param string $order MySQL ORDER BY clause (NULL to order by date)
|
||||
* @param int|array $limit Limit clause
|
||||
* @param string $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index
|
||||
* @param mixed $includeHiddenItems Include hidden comments? NULL to detect if currently logged in member has permission, -1 to return public content only, TRUE to return unapproved content and FALSE to only return unapproved content the viewing member submitted
|
||||
* @param int $queryFlags Select bitwise flags
|
||||
* @param \IPS\Member $member The member (NULL to use currently logged in member)
|
||||
* @param bool $joinContainer If true, will join container data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinComments If true, will join comment data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinReviews If true, will join review data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $countOnly If true will return the count
|
||||
* @param array|null $joins Additional arbitrary joins for the query
|
||||
* @return array|NULL|\IPS\Content\Comment If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
|
||||
* @param array $where Where clause
|
||||
* @param string|null $order MySQL ORDER BY clause (NULL to order by date)
|
||||
* @param int|array|null $limit Limit clause
|
||||
* @param string|null $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index
|
||||
* @param mixed $includeHiddenComments
|
||||
* @param int $queryFlags Select bitwise flags
|
||||
* @param Member|null $member The member (NULL to use currently logged in member)
|
||||
* @param bool $joinContainer If true, will join container data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinComments If true, will join comment data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinReviews If true, will join review data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $countOnly If true will return the count
|
||||
* @param array|null $joins Additional arbitrary joins for the query
|
||||
* @return array|NULL|Comment If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
|
||||
*/
|
||||
public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=\IPS\Content\Hideable::FILTER_AUTOMATIC, $queryFlags=0, \IPS\Member $member=NULL, $joinContainer=FALSE, $joinComments=FALSE, $joinReviews=FALSE, $countOnly=FALSE, $joins=NULL )
|
||||
public static function getItemsWithPermission( array $where=array(), string $order= null, int|array|null $limit=10, string|null $permissionKey='read', mixed $includeHiddenComments= Filter::FILTER_AUTOMATIC, int $queryFlags=0, Member|null $member= null, bool $joinContainer=FALSE, bool $joinComments=FALSE, bool $joinReviews=FALSE, bool $countOnly=FALSE, array|null $joins= null ): mixed
|
||||
{
|
||||
$class = '\IPS\cms\Records' . static::$customDatabaseId;
|
||||
|
||||
/* @var $class Records */
|
||||
$where = $class::getItemsWithPermissionWhere( $where, $permissionKey, $member, $joinContainer );
|
||||
|
||||
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenItems, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML for search result display
|
||||
*
|
||||
* @param array $indexData Data from the search index
|
||||
* @param array $authorData Basic data about the author. Only includes columns returned by \IPS\Member::columnsForPhoto()
|
||||
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
|
||||
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
|
||||
* @param array $reputationData Array of people who have given reputation and the reputation they gave
|
||||
* @param int|NULL $reviewRating If this is a review, the rating
|
||||
* @param bool $iPostedIn If the user has posted in the item
|
||||
* @param string $view 'expanded' or 'condensed'
|
||||
* @param bool $asItem Displaying results as items?
|
||||
* @param bool $canIgnoreComments Can ignore comments in the result stream? Activity stream can, but search results cannot.
|
||||
* @param array $template Optional custom template
|
||||
* @param array $reactions Reaction Data
|
||||
* @return string
|
||||
*/
|
||||
public static function searchResult( array $indexData, array $authorData, array $itemData, ?array $containerData, array $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments=FALSE, $template=NULL, $reactions=array() )
|
||||
{
|
||||
/* Ensure that the comment title is formatted correctly */
|
||||
try
|
||||
{
|
||||
$databases = \IPS\cms\Databases::databases();
|
||||
|
||||
if ( ! isset( static::$searchIndexTitles[ $itemData['primary_id_field'] ] ) )
|
||||
{
|
||||
$fields = '\IPS\cms\Fields' . static::$customDatabaseId;
|
||||
$titleField = $databases[ static::$customDatabaseId ]->field_title;
|
||||
|
||||
static::$searchIndexTitles[ $itemData['primary_id_field'] ] = $fields::load( $databases[ static::$customDatabaseId ]->field_title )->displayValue( $itemData['field_' . $databases[ static::$customDatabaseId ]->field_title ] );
|
||||
}
|
||||
|
||||
$itemData['field_' . $databases[ static::$customDatabaseId ]->field_title ] = static::$searchIndexTitles[ $itemData['primary_id_field'] ];
|
||||
}
|
||||
catch ( \Exception $ex ) { }
|
||||
|
||||
return parent::searchResult( $indexData, $authorData, $itemData, $containerData, $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments, $template, $reactions );
|
||||
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenComments, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,13 +224,14 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postCreate()
|
||||
public function postCreate(): void
|
||||
{
|
||||
$this->database_id = static::$customDatabaseId;
|
||||
$this->save();
|
||||
|
||||
$item = $this->item();
|
||||
if ( $item->hidden() OR ( \IPS\cms\Databases::load( static::$customDatabaseId )->_comment_bump & \IPS\cms\Databases::BUMP_ON_COMMENT ) )
|
||||
/* @var $item Records */
|
||||
if ( $item->hidden() OR ( Databases::load( static::$customDatabaseId )->_comment_bump & Databases::BUMP_ON_COMMENT ) )
|
||||
{
|
||||
parent::postCreate();
|
||||
}
|
||||
@@ -270,7 +257,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
$template = static::$commentTemplate[1];
|
||||
static::$commentTemplate[0][0] = $this->item()->database()->template_display;
|
||||
@@ -282,9 +269,9 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
* Get URL for doing stuff
|
||||
*
|
||||
* @param string|NULL $action Action
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url
|
||||
*/
|
||||
public function url( $action='find' )
|
||||
public function url( ?string $action='find' ): Url
|
||||
{
|
||||
$url = parent::url( $action );
|
||||
|
||||
@@ -303,7 +290,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachmentIds()
|
||||
public function attachmentIds(): array
|
||||
{
|
||||
$item = $this->item();
|
||||
$idColumn = $item::$databaseColumnId;
|
||||
@@ -316,27 +303,17 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
public static function commentWhere()
|
||||
public static function commentWhere(): ?array
|
||||
{
|
||||
return array( 'comment_database_id=?', static::$customDatabaseId );
|
||||
}
|
||||
|
||||
/**
|
||||
* WHERE clause for getting items for ACP overview statistics
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function overviewStatisticsWhere()
|
||||
{
|
||||
return [ static::commentWhere() ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reaction Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function reactionType()
|
||||
public static function reactionType(): string
|
||||
{
|
||||
$databaseId = static::$customDatabaseId;
|
||||
return "comment_id_{$databaseId}";
|
||||
@@ -348,9 +325,9 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
* @param array $params Additional parameters to add to URL
|
||||
* @return string
|
||||
*/
|
||||
public function embedContent( $params )
|
||||
public function embedContent( array $params ): string
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'embed.css', 'cms', 'front' ) );
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'cms' )->embedRecordComment( $this, $this->item(), $this->url()->setQueryString( $params ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'embed.css', 'cms', 'front' ) );
|
||||
return Theme::i()->getTemplate( 'global', 'cms' )->embedRecordComment( $this, $this->item(), $this->url()->setQueryString( $params ) );
|
||||
}
|
||||
}
|
||||
@@ -12,41 +12,53 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Records;
|
||||
use IPS\cms\Theme;
|
||||
use IPS\Content\Item;
|
||||
use IPS\core\Reports\Report;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use UnexpectedValueException;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Records Model
|
||||
*/
|
||||
class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
class CommentTopicSync extends Comment
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'pid';
|
||||
public static string $databaseColumnId = 'pid';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'forums_posts';
|
||||
public static ?string $databaseTable = 'forums_posts';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = '';
|
||||
public static string $databasePrefix = '';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'item' => 'topic_id',
|
||||
'author' => 'author_id',
|
||||
'author_name' => 'author_name',
|
||||
@@ -64,27 +76,27 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'forums';
|
||||
public static string $application = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'comment';
|
||||
public static string $icon = 'comment';
|
||||
|
||||
/**
|
||||
* @brief [Content] Key for hide reasons
|
||||
*/
|
||||
public static $hideLogKey = 'post';
|
||||
public static ?string $hideLogKey = 'post';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Comment Template
|
||||
*/
|
||||
public static $commentTemplate = array( array( 'display', 'cms', 'database' ), 'commentContainer' );
|
||||
public static array $commentTemplate = array( array( 'display', 'cms', 'database' ), 'commentContainer' );
|
||||
|
||||
/**
|
||||
* @brief Bitwise values for post_bwoptions field
|
||||
*/
|
||||
public static $bitOptions = array(
|
||||
public static array $bitOptions = array(
|
||||
'post_bwoptions' => array(
|
||||
'post_bwoptions' => array(
|
||||
'best_answer' => 1
|
||||
@@ -95,11 +107,12 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
/**
|
||||
* Get containing item
|
||||
*
|
||||
* @return \IPS\cms\Record
|
||||
* @return Item
|
||||
*/
|
||||
public function item()
|
||||
public function item(): Item
|
||||
{
|
||||
$itemClass = static::$itemClass;
|
||||
/* @var $itemClass Records */
|
||||
$lookFor = 'IPS\cms\Records\RecordsTopicSync';
|
||||
|
||||
if ( mb_substr( $itemClass, 0, mb_strlen( $lookFor ) ) === $lookFor )
|
||||
@@ -108,7 +121,7 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
}
|
||||
else
|
||||
{
|
||||
$id = \IPS\Request::i()->id;
|
||||
$id = Request::i()->id;
|
||||
}
|
||||
|
||||
return $itemClass::load( $id );
|
||||
@@ -117,24 +130,24 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
/**
|
||||
* Delete Comment
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
/* We need the classname to be \IPS\forums\Topic\Post so topic/forum sync occur and to ensure post is removed from search index */
|
||||
$comment = \IPS\forums\Topic\Post::load( $this->pid );
|
||||
$comment = Post::load( $this->pid );
|
||||
$comment->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Comment Contents - Note: does not add edit log
|
||||
*
|
||||
* @param string $newContent New content
|
||||
* @return string|NULL
|
||||
* @param string $newContent New content
|
||||
* @return void
|
||||
*/
|
||||
public function editContents( $newContent )
|
||||
public function editContents( string $newContent ): void
|
||||
{
|
||||
$comment = \IPS\forums\Topic\Post::load( $this->pid );
|
||||
$comment = Post::load( $this->pid );
|
||||
$comment->editContents( $newContent );
|
||||
}
|
||||
|
||||
@@ -143,19 +156,19 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
if ( ! empty( $this->pid ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$comment = \IPS\forums\Topic\Post::load( $this->pid );
|
||||
$comment = Post::load( $this->pid );
|
||||
$template = static::$commentTemplate[1];
|
||||
static::$commentTemplate[0][0] = $this->item()->database()->template_display;
|
||||
|
||||
return \IPS\cms\Theme::i()->getTemplate( static::$commentTemplate[0][0], static::$commentTemplate[0][1], static::$commentTemplate[0][2] )->$template( $comment->item(), $comment );
|
||||
return Theme::i()->getTemplate( static::$commentTemplate[0][0], static::$commentTemplate[0][1], static::$commentTemplate[0][2] )->$template( $comment->item(), $comment );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
return parent::html();
|
||||
}
|
||||
@@ -165,20 +178,19 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
return parent::html();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Report
|
||||
*
|
||||
* @param string $reportContent Report content message from member
|
||||
* @param int $reportType Report type (see constants in \IPS\core\Reports\Report)
|
||||
* @param \IPS\Member|NULL $member Member making the report (or NULL for loggedIn())
|
||||
* @param array $guestDetails Details for a guest report
|
||||
* @return \IPS\core\Reports\Report
|
||||
* @throws \UnexpectedValueException If there is a permission error - you should only call this method after checking canReport
|
||||
* @param string $reportContent Report content message from member
|
||||
* @param int $reportType Report type (see constants in \IPS\core\Reports\Report
|
||||
* @param Member|null $member Member making the report (or NULL for loggedIn())
|
||||
* @return Report
|
||||
* @throws UnexpectedValueException If there is a permission error - you should only call this method after checking canReport
|
||||
*/
|
||||
public function report( $reportContent, $reportType=1, $member=NULL, $guestDetails=array() )
|
||||
public function report( string $reportContent, int $reportType=1, Member|null $member=null ): Report
|
||||
{
|
||||
$comment = \IPS\forums\Topic\Post::load( $this->pid );
|
||||
$comment = Post::load( $this->pid );
|
||||
return $comment->report( $reportContent, $reportType, $member );
|
||||
}
|
||||
|
||||
@@ -187,7 +199,7 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
public static function commentWhere()
|
||||
public static function commentWhere(): ?array
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -198,7 +210,7 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
* @param int $id Content item to delete from
|
||||
* @return array
|
||||
*/
|
||||
public static function deleteWhereSql( $id )
|
||||
public static function deleteWhereSql( int $id ): array
|
||||
{
|
||||
return array( array( static::$databasePrefix . static::$databaseColumnMap['item'] . '=?', $id ) );
|
||||
}
|
||||
@@ -206,12 +218,12 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
/**
|
||||
* Post count for member
|
||||
*
|
||||
* @param \IPS\Member $member The member
|
||||
* @param Member $member The member
|
||||
* @param bool $includeNonPostCountIncreasing If FALSE, will skip any posts which would not cause the user's post count to increase
|
||||
* @param bool $includeHiddenAndPendingApproval If FALSE, will skip any hidden posts, or posts pending approval
|
||||
* @return int
|
||||
*/
|
||||
public static function memberPostCount( \IPS\Member $member, bool $includeNonPostCountIncreasing = FALSE, bool $includeHiddenAndPendingApproval = TRUE )
|
||||
public static function memberPostCount( Member $member, bool $includeNonPostCountIncreasing = FALSE, bool $includeHiddenAndPendingApproval = TRUE ): int
|
||||
{
|
||||
return 0; // We explicitely return 0 because any posts will be counted via the forums application inherently already
|
||||
}
|
||||
@@ -221,7 +233,7 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function reactionType()
|
||||
public static function reactionType(): string
|
||||
{
|
||||
return 'pid';
|
||||
}
|
||||
@@ -231,7 +243,7 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function reactionClass()
|
||||
public static function reactionClass() : string
|
||||
{
|
||||
return 'IPS\forums\Topic\Post';
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,58 +12,79 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use BadMethodCallException;
|
||||
use IPS\Content\EditHistory;
|
||||
use IPS\Content\Embeddable;
|
||||
use IPS\Content\Filter;
|
||||
use IPS\Content\Hideable;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Content\Reactable;
|
||||
use IPS\Content\Reportable;
|
||||
use IPS\Content\Review as ContentReview;
|
||||
use IPS\Content\Shareable;
|
||||
use IPS\DateTime;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Exception;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
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 Model
|
||||
*/
|
||||
class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Shareable, \IPS\Content\Searchable, \IPS\Content\Embeddable
|
||||
class Review extends ContentReview implements Embeddable,
|
||||
Filter
|
||||
{
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable;
|
||||
use Reactable, Reportable, Shareable, EditHistory, Hideable;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Item Class
|
||||
*/
|
||||
public static $itemClass = NULL;
|
||||
public static ?string $itemClass = NULL;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'cms_database_reviews';
|
||||
public static ?string $databaseTable = 'cms_database_reviews';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'review_';
|
||||
public static string $databasePrefix = 'review_';
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'cms';
|
||||
public static string $application = 'cms';
|
||||
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'content_review';
|
||||
public static string $title = 'content_review';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'item' => 'item',
|
||||
'author' => 'author',
|
||||
'author_name' => 'author_name',
|
||||
@@ -84,30 +105,28 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'comment';
|
||||
public static string $icon = 'star';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Comment Template
|
||||
*/
|
||||
public static $commentTemplate = array( array( 'display', 'cms', 'database' ), 'reviewContainer' );
|
||||
public static array $commentTemplate = array( array( 'display', 'cms', 'database' ), 'reviewContainer' );
|
||||
|
||||
/**
|
||||
* @brief Database ID
|
||||
*/
|
||||
public static $customDatabaseId = NULL;
|
||||
public static ?int $customDatabaseId = NULL;
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details) - if used will cause multiton store to be skipped and a query always ran
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
* @param int|string|null $id ID
|
||||
* @param string|null $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details) - if used will cause multiton store to be skipped and a query always ran
|
||||
* @return ActiveRecord|Review
|
||||
* @see \IPS\Db::build
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
public static function load( int|string|null $id, string $idField=NULL, mixed $extraWhereClause=NULL ): ActiveRecord|static
|
||||
{
|
||||
if( $extraWhereClause === NULL )
|
||||
{
|
||||
@@ -124,52 +143,42 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
/**
|
||||
* Create first comment (created with content item)
|
||||
*
|
||||
* @param \IPS\Content\Item $item The content item just created
|
||||
* @param string $comment The comment
|
||||
* @param bool $first Is the first comment?
|
||||
* @param int $rating The rating (1-5)
|
||||
* @param string $guestName If author is a guest, the name to use
|
||||
* @param \IPS\Member|NULL $member The author of this comment. If NULL, uses currently logged in member.
|
||||
* @param \IPS\DateTime|NULL $time The time
|
||||
* @param string|NULL $ipAddress The IP address or NULL to detect automatically
|
||||
* @param int|NULL $hiddenStatus NULL to set automatically or override: 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
|
||||
* @param int|NULL $anonymous NULL for no value, 0 or 1 for a value (0=no, 1=yes)
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @param Item $item The content item just created
|
||||
* @param string $comment The comment
|
||||
* @param bool $first Is the first comment?
|
||||
* @param string|null $guestName If author is a guest, the name to use
|
||||
* @param bool|null $incrementPostCount
|
||||
* @param Member|null $member The author of this comment. If NULL, uses currently logged in member.
|
||||
* @param DateTime|null $time The time
|
||||
* @param string|null $ipAddress The IP address or NULL to detect automatically
|
||||
* @param int|null $hiddenStatus NULL to set automatically or override: 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
|
||||
* @param int|null $anonymous NULL for no value, 0 or 1 for a value (0=no, 1=yes)
|
||||
* @return Review|null
|
||||
*/
|
||||
public static function create( $item, $comment, $first=FALSE, $rating=NULL, $guestName=NULL, $member=NULL, \IPS\DateTime $time=NULL, $ipAddress=NULL, $hiddenStatus=NULL, $anonymous=NULL )
|
||||
public static function create( Item $item, string $comment, bool $first=false, string|null $guestName=null, bool|null $incrementPostCount= null, Member|null $member= null, DateTime|null $time= null, string|null $ipAddress= null, int|null $hiddenStatus= null, int|null $anonymous= null ): static|null
|
||||
{
|
||||
$review = parent::create( $item, $comment, $first, $rating, $guestName, $member, $time, $ipAddress, $hiddenStatus, $anonymous );
|
||||
$review = parent::create( $item, $comment, $first, $guestName, $member, $time, $ipAddress, $hiddenStatus, $anonymous );
|
||||
|
||||
$review->database_id = static::$customDatabaseId;
|
||||
$review->save();
|
||||
|
||||
/* Have to do these AFTER database id is set */
|
||||
/* @var array $databaseColumnMap */
|
||||
$ratingField = $item::$databaseColumnMap['rating'];
|
||||
|
||||
$review->item()->$ratingField = $review->item()->averageReviewRating() ?: 0;
|
||||
$review->item()->$ratingField = (int) $review->item()->averageReviewRating() ?: 0;
|
||||
$review->item()->save();
|
||||
|
||||
return $review;
|
||||
}
|
||||
|
||||
/**
|
||||
* WHERE clause for getting items for ACP overview statistics
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function overviewStatisticsWhere()
|
||||
{
|
||||
return [ static::commentWhere() ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return custom where for SQL delete
|
||||
*
|
||||
* @param int $id Content item to delete from
|
||||
* @return array
|
||||
*/
|
||||
public static function deleteWhereSql( $id )
|
||||
public static function deleteWhereSql( int $id ) : array
|
||||
{
|
||||
return array( array( static::$databasePrefix . static::$databaseColumnMap['item'] . '=?', $id ), array( static::$databasePrefix . 'database_id=?', static::$customDatabaseId ) );
|
||||
}
|
||||
@@ -179,7 +188,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
$template = static::$commentTemplate[1];
|
||||
static::$commentTemplate[0][0] = $this->item()->database()->template_display;
|
||||
@@ -191,11 +200,11 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
* Get URL for doing stuff
|
||||
*
|
||||
* @param string|NULL $action Action
|
||||
* @return \IPS\Http\Url
|
||||
* @throws \BadMethodCallException
|
||||
* @throws \IPS\Http\Url\Exception
|
||||
* @return Url
|
||||
* @throws BadMethodCallException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function url( $action='find' )
|
||||
public function url( ?string $action='find' ): Url
|
||||
{
|
||||
$url = parent::url( $action );
|
||||
|
||||
@@ -212,7 +221,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachmentIds()
|
||||
public function attachmentIds(): array
|
||||
{
|
||||
$item = $this->item();
|
||||
$idColumn = $item::$databaseColumnId;
|
||||
@@ -225,7 +234,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
public static function commentWhere()
|
||||
public static function commentWhere(): ?array
|
||||
{
|
||||
return array( 'review_database_id=?', static::$customDatabaseId );
|
||||
}
|
||||
@@ -236,7 +245,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
* @return string
|
||||
* @todo This was implemented improperly before - look into upgrade routine to fix
|
||||
*/
|
||||
public static function reactionType()
|
||||
public static function reactionType(): string
|
||||
{
|
||||
$databaseId = static::$customDatabaseId;
|
||||
return "review_id_{$databaseId}";
|
||||
@@ -248,9 +257,9 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
* @param array $params Additional parameters to add to URL
|
||||
* @return string
|
||||
*/
|
||||
public function embedContent( $params )
|
||||
public function embedContent( array $params ): string
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'embed.css', 'cms', 'front' ) );
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'cms' )->embedRecordReview( $this, $this->item(), $this->url()->setQueryString( $params ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'embed.css', 'cms', 'front' ) );
|
||||
return Theme::i()->getTemplate( 'global', 'cms' )->embedRecordReview( $this, $this->item(), $this->url()->setQueryString( $params ) );
|
||||
}
|
||||
}
|
||||
@@ -12,41 +12,50 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Fields;
|
||||
use IPS\cms\Records;
|
||||
use IPS\Login;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Records Model
|
||||
*/
|
||||
class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
class Revisions extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons = array();
|
||||
protected static array $multitons = array();
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'cms_database_revisions';
|
||||
public static ?string $databaseTable = 'cms_database_revisions';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'revision_';
|
||||
public static string $databasePrefix = 'revision_';
|
||||
|
||||
/**
|
||||
* @brief Unpacked data
|
||||
*/
|
||||
protected $_dataJson = NULL;
|
||||
protected ?array $_dataJson = NULL;
|
||||
|
||||
/**
|
||||
* Constructor - Create a blank object with default values
|
||||
@@ -59,7 +68,7 @@ class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
if ( $this->_new )
|
||||
{
|
||||
$this->member_id = \IPS\Member::loggedIn()->member_id;
|
||||
$this->member_id = Member::loggedIn()->member_id;
|
||||
$this->date = time();
|
||||
}
|
||||
}
|
||||
@@ -70,7 +79,7 @@ class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
* @param string $key Key of value to return
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $key )
|
||||
public function get( string $key ) : mixed
|
||||
{
|
||||
if ( $this->_dataJson === NULL )
|
||||
{
|
||||
@@ -88,14 +97,15 @@ class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Compute differences
|
||||
*
|
||||
* @param int $databaseId Database ID
|
||||
* @param \IPS\cms\Records $record Record
|
||||
* @param boolean $justChanged Get changed only
|
||||
* @param int $databaseId Database ID
|
||||
* @param Records $record Record
|
||||
* @param boolean $justChanged Get changed only
|
||||
* @return array
|
||||
*/
|
||||
public function getDiffHtmlTables( $databaseId, $record, $justChanged=FALSE )
|
||||
public function getDiffHtmlTables( int $databaseId, Records $record, bool $justChanged=FALSE ): array
|
||||
{
|
||||
$fieldsClass = 'IPS\cms\Fields' . $databaseId;
|
||||
/* @var $fieldsClass Fields */
|
||||
$customFields = $fieldsClass::data( 'view' );
|
||||
$conflicts = array();
|
||||
|
||||
@@ -104,7 +114,7 @@ class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$key = 'field_' . $field->id;
|
||||
|
||||
if( $justChanged === FALSE OR !\IPS\Login::compareHashes( md5( $record->$key ), md5( $this->get( $key ) ) ) )
|
||||
if( $justChanged === FALSE OR !Login::compareHashes( md5( $record->$key ), md5( $this->get( $key ) ) ) )
|
||||
{
|
||||
$conflicts[] = array( 'original' => $this->get( $key ), 'current' => $record->$key, 'field' => $field );
|
||||
}
|
||||
@@ -119,9 +129,9 @@ class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
* @param string|array $value
|
||||
* @return void
|
||||
*/
|
||||
public function set_data( $value )
|
||||
public function set_data( string|array $value ) : void
|
||||
{
|
||||
$this->_data['data'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['data'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +139,7 @@ class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_data()
|
||||
public function get_data() : array
|
||||
{
|
||||
return json_decode( $this->_data['data'], TRUE );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user