Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

+73 -54
View File
@@ -291,6 +291,31 @@ abstract class Comment extends Content
$member->save();
}
/* Send webhook */
if ( IPS::classUsesTrait( $obj, 'IPS\Content\Hideable' ) and in_array( $obj->hidden(), array( -1, 0, 1 ) ) ) // i.e. not post before register or pending deletion
{
Webhook::fire( str_replace( '\\', '', substr( get_called_class(), 3 ) ) . '_create', $obj, $obj->webhookFilters() );
}
/* DataLayer Event */
if ( DataLayer::enabled() and static::dataLayerEventActive( 'comment_create' ) and !( $item::$firstCommentRequired and $obj->isFirst() ) )
{
$obj->_dataLayerProperties = [];
$event = 'comment_create';
$properties = $obj->getDataLayerProperties();
/* todo this should probably be deleted as I'm not sure why it's here. Leaving here for a reference just in case */
// if ( $properties['content_area'] === 'personal_messages' )
// {
// return NULL;
// }
DataLayer::i()->addEvent( $event, $properties );
}
/* Update item */
$obj->postCreate();
/* Send notifications and dish out points */
if ( !in_array( 'IPS\Content\Review', class_parents( get_called_class() ) ) )
{
@@ -307,34 +332,6 @@ abstract class Comment extends Content
$obj->sendUnapprovedNotification();
}
}
/* Send webhook */
if ( IPS::classUsesTrait( $obj, 'IPS\Content\Hideable' ) and in_array( $obj->hidden(), array( -1, 0, 1 ) ) ) // i.e. not post before register or pending deletion
{
Webhook::fire( str_replace( '\\', '', substr( get_called_class(), 3 ) ) . '_create', $obj, $obj->webhookFilters() );
}
/* DataLayer Event */
if ( Settings::i()->core_datalayer_enabled and !( $item::$firstCommentRequired and $obj->isFirst() ) )
{
$event = 'comment_create';
$properties = $obj->getDataLayerProperties();
if ( $properties['content_area'] === 'personal_messages' )
{
return NULL;
}
$properties = array_merge( $properties, array(
'author_id' => $obj->author()->member_id,
'author_name' => $obj->author()->name ?? 'Guest',
) );
DataLayer::i()->addEvent( $event, $properties );
}
/* Update item */
$obj->postCreate();
/* This needs to happen before the index is added */
if( $item::$firstCommentRequired and $obj->isFirst() )
@@ -372,13 +369,7 @@ abstract class Comment extends Content
{
if ( empty( $this->_dataLayerProperties ) )
{
$item = $this->item();
$this->_dataLayerProperties = $item->getDataLayerProperties( $this );
if ( $this->_dataLayerProperties['content_type'] === 'question' )
{
$this->_dataLayerProperties['comment_type'] = 'answer';
}
$this->_dataLayerProperties = DataLayer::i()->filterProperties( $this->_dataLayerProperties );
$this->_dataLayerProperties = $this->item()->getDataLayerProperties( $this, clearCache: true );
}
return $this->_dataLayerProperties;
@@ -728,6 +719,12 @@ abstract class Comment extends Content
*/
public function canView( Member|null $member= null ): bool
{
/* Extensions go first */
if( $permCheck = Permissions::can( 'view', $this, $member ) )
{
return ( $permCheck === Permissions::PERM_ALLOW );
}
if( $member === NULL )
{
$member = Member::loggedIn();
@@ -749,6 +746,12 @@ abstract class Comment extends Content
*/
public function canEdit( Member|null $member=NULL ): bool
{
/* Extensions go first */
if( $permCheck = Permissions::can( 'edit', $this, $member ) )
{
return ( $permCheck === Permissions::PERM_ALLOW );
}
if( !$this->actionEnabled( 'edit', $member ) )
{
return false;
@@ -805,6 +808,12 @@ abstract class Comment extends Content
*/
public function canDelete( Member|null $member=NULL ): bool
{
/* Extensions go first */
if( $permCheck = Permissions::can( 'delete', $this, $member ) )
{
return ( $permCheck === Permissions::PERM_ALLOW );
}
if( !$this->actionEnabled( 'delete', $member ) )
{
return false;
@@ -823,6 +832,12 @@ abstract class Comment extends Content
*/
public function canSplit( Member|null $member=null ): bool
{
/* Extensions go first */
if( $permCheck = Permissions::can( 'split', $this, $member ) )
{
return ( $permCheck === Permissions::PERM_ALLOW );
}
if( !$this->actionEnabled( 'split', $member ) )
{
return false;
@@ -869,14 +884,7 @@ abstract class Comment extends Content
*/
public function dateLine(): string
{
if( $this->mapped('first') )
{
return Member::loggedIn()->language()->addToStack( static::$formLangPrefix . 'date_started', FALSE, array( 'htmlsprintf' => array( DateTime::ts( $this->mapped('date') )->html() ) ) );
}
else
{
return Member::loggedIn()->language()->addToStack( static::$formLangPrefix . 'date_replied', FALSE, array( 'htmlsprintf' => array( DateTime::ts( $this->mapped('date') )->html() ) ) );
}
return Member::loggedIn()->language()->addToStack( static::$formLangPrefix . 'date_replied', FALSE, array( 'htmlsprintf' => array( DateTime::ts( $this->mapped('date') )->html() ) ) );
}
/**
@@ -1014,11 +1022,8 @@ abstract class Comment extends Content
Db::i()->update( 'core_reputation_index', array( 'item_id' => $item->$idColumn ), array( 'class_type_id_hash=?', md5( get_class( $this ) . ':' . $oldItem->$idColumn ) ) );
}
/* Update solved */
if ( IPS::classUsesTrait( $this, 'IPS\Content\Solvable' ) )
{
Db::i()->update( 'core_solved_index', array( 'item_id' => $item->$idColumn ), array( 'comment_class=? and comment_id=?', get_class( $this ), $oldItem->$idColumn ) );
}
/* Update solved - do this without checking for the trait, because multiple traits use it */
Db::i()->update( 'core_solved_index', array( 'item_id' => $item->$idColumn ), array( 'comment_class=? and comment_id=?', get_class( $this ), $this->$commentIdColumn ) );
/* Update member map */
try
@@ -1037,6 +1042,13 @@ abstract class Comment extends Content
if( $skip === FALSE )
{
/* Update Helpfuls */
if( IPS::classUsesTrait( $this, Helpful::class ) and isset( $item::$databaseColumnMap['num_helpful'] ) )
{
$oldItem->recountHelpfuls();
$item->recountHelpfuls();
}
$oldItem->rebuildFirstAndLastCommentData();
$item->rebuildFirstAndLastCommentData();
@@ -1119,7 +1131,7 @@ abstract class Comment extends Content
}
/* Remove featured comment associations */
if( $item and IPS::classUsesTrait( $item, 'IPS\Content\MetaData' ) and $this->isFeatured() )
if( $item and $this->isFeaturedComment() )
{
Application::load('core')->extensions( 'core', 'MetaData' )['FeaturedComments']->unfeatureComment( $item, $this );
}
@@ -1186,16 +1198,23 @@ abstract class Comment extends Content
if ( $item->mapped('solved_comment_id') and $item->mapped('solved_comment_id') == $this->$idColumn )
{
Db::i()->update( $itemClass::$databaseTable, array( $itemClass::$databaseColumnMap['solved_comment_id'] => 0 ), array( $itemIdColumn . '=?', $itemId ) );
Db::i()->delete( 'core_solved_index', array( 'app=? and comment_class=? and item_id=? and comment_id=?', static::$application, get_called_class(), $itemId, $this->$idColumn ) );
}
}
/* Clear the solved index regardless of trait; multiple traits use it */
Db::i()->delete( 'core_solved_index', array( 'app=? and comment_class=? and item_id=? and comment_id=?', static::$application, get_called_class(), $itemId, $this->$idColumn ) );
if ( $item AND IPS::classUsesTrait( $this->item(), 'IPS\Content\Statistics' ) )
{
$item->clearCachedStatistics( TRUE );
}
/* Update helpfuls */
if( IPS::classUsesTrait( $this, Helpful::class ) and IPS::classUsesTrait( $item, Helpful::class ) )
{
$item->recountHelpfuls();
}
/* Delete any notifications telling people about this */
$memberIds = array();
@@ -1516,7 +1535,7 @@ abstract class Comment extends Content
/* @var array $databaseColumnMap */
/* Finally, we do not want posts from future items */
if ( in_array( 'IPS\Content\FuturePublishing', class_implements( $itemClass ) ) )
if( IPS::classUsesTrait( $itemClass, FuturePublishing::class ) )
{
$itemWhere[] = array( $itemClass::$databasePrefix . $itemClass::$databaseColumnMap['is_future_entry'] . '=0' );
}
@@ -1739,9 +1758,9 @@ abstract class Comment extends Content
*/
public function isFeaturedComment(): bool
{
if ( IPS::classUsesTrait( $this->item(), 'IPS\Content\MetaData' ) )
if ( !( $this instanceof Review ) and IPS::classUsesTrait( $this->item(), 'IPS\Content\MetaData' ) )
{
return Application::load('core')->extensions( 'core', 'MetaData' )['FeaturedComments']->isFeaturedComment( $this );
return Application::load('core')->extensions( 'core', 'MetaData' )['FeaturedComments']->isCommentShownAtTheTop( $this );
}
return FALSE;