Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -25,7 +25,9 @@ use IPS\Content\Item;
|
||||
use IPS\Content\Review;
|
||||
use IPS\Content\Solvable;
|
||||
use IPS\core\Approval;
|
||||
use IPS\core\DataLayer;
|
||||
use IPS\core\Reports\Report;
|
||||
use IPS\core\Reports\Types;
|
||||
use IPS\Db\Select;
|
||||
use IPS\Events\Event;
|
||||
use IPS\Http\Url;
|
||||
@@ -76,6 +78,7 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
* @mixin \IPS\Content\EditHistory
|
||||
* @mixin \IPS\Content\Followable
|
||||
* @mixin \IPS\Content\FuturePublishing
|
||||
* @mixin \IPS\Content\Helpful
|
||||
* @mixin \IPS\Content\Hideable
|
||||
* @mixin \IPS\Content\ItemTopic
|
||||
* @mixin \IPS\Content\Lockable
|
||||
@@ -125,6 +128,12 @@ abstract class Content extends ActiveRecord
|
||||
*/
|
||||
public static bool $canBeModeratedFromFrontend = TRUE;
|
||||
|
||||
/**
|
||||
* An array containing data layer event keys to bypass. Optionally, this can be set to 'true' to bypass all events.
|
||||
* @var bool|string[]
|
||||
*/
|
||||
protected static array|bool $_bypassDataLayerEvents = [];
|
||||
|
||||
/**
|
||||
* Should posting this increment the poster's post count?
|
||||
*
|
||||
@@ -680,6 +689,7 @@ abstract class Content extends ActiveRecord
|
||||
Webhook::fire( str_replace( '\\', '', substr( get_called_class(), 3 ) ) . '_modaction', ['action' => $action, 'item' => $this->apiOutput()], $this->webhookFilters() );
|
||||
|
||||
/* These ones just need a property setting */
|
||||
$dataLayerEvent = null;
|
||||
if ( in_array( $action, array( 'pin', 'unpin', 'feature', 'unfeature', 'lock', 'unlock' ) ) )
|
||||
{
|
||||
$val = TRUE;
|
||||
@@ -714,6 +724,11 @@ abstract class Content extends ActiveRecord
|
||||
$this->$column = $val;
|
||||
$this->save();
|
||||
|
||||
if ( $action === 'pin' or $action === 'unpin' )
|
||||
{
|
||||
$dataLayerEvent = $action === 'pin' ? 'pin' : 'unpin';
|
||||
}
|
||||
|
||||
/* Fire events for these here, the others will be fired at a later point */
|
||||
Event::fire( 'onStatusChange', $this, array( $action ) );
|
||||
}
|
||||
@@ -721,10 +736,12 @@ abstract class Content extends ActiveRecord
|
||||
/* Hide is a tiny bit more complicated */
|
||||
elseif ( $action === 'hide' )
|
||||
{
|
||||
$dataLayerEvent = 'hide';
|
||||
$this->hide( $member, $reason );
|
||||
}
|
||||
elseif ( $action === 'unhide' )
|
||||
{
|
||||
$dataLayerEvent = 'unhide';
|
||||
$this->unhide( $member );
|
||||
}
|
||||
|
||||
@@ -737,8 +754,8 @@ abstract class Content extends ActiveRecord
|
||||
$this->logDelete( $member );
|
||||
return;
|
||||
}
|
||||
|
||||
$idColumn = static::$databaseColumnId;
|
||||
|
||||
$dataLayerEvent = 'delete';
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
@@ -769,6 +786,11 @@ abstract class Content extends ActiveRecord
|
||||
$this->move( $args[2][0], $args[2][1] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $dataLayerEvent and DataLayer::enabled( 'analytics_full' ) and static::dataLayerEventActive( 'content_' . $dataLayerEvent ) )
|
||||
{
|
||||
DataLayer::i()->addEvent( 'content_' . $dataLayerEvent, $this->getDataLayerProperties() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -902,6 +924,7 @@ abstract class Content extends ActiveRecord
|
||||
$item = ( $this instanceof Comment ) ? $this->item() : $this;
|
||||
$itemIdColumn = $item::$databaseColumnId;
|
||||
|
||||
$new = false;
|
||||
try
|
||||
{
|
||||
$index = Report::load( $this->$idColumn, 'content_id', array( 'class=?', get_called_class() ) );
|
||||
@@ -909,6 +932,7 @@ abstract class Content extends ActiveRecord
|
||||
}
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
$new = true;
|
||||
$index = new Report;
|
||||
$index->class = get_called_class();
|
||||
$index->content_id = $this->$idColumn;
|
||||
@@ -991,7 +1015,7 @@ abstract class Content extends ActiveRecord
|
||||
}
|
||||
}
|
||||
|
||||
$notification = new Notification( Application::load('core'), 'report_center', $index, array( $index, $reportInsert, $this ) );
|
||||
$notification = new Notification( Application::load('core'), 'report_center', $index, array( $index, $reportInsert, $this, $member ) );
|
||||
foreach (Db::i()->select( '*', 'core_members', ( count( $moderators['m'] ) ? Db::i()->in( 'member_id', $moderators['m'] ) . ' OR ' : '' ) . Db::i()->in( 'member_group_id', $moderators['g'] ) . ' OR ' . Db::i()->findInSet( 'mgroup_others', $moderators['g'] ) ) as $mem )
|
||||
{
|
||||
$memberObj = Member::constructFromData( $mem );
|
||||
@@ -1022,6 +1046,33 @@ abstract class Content extends ActiveRecord
|
||||
$this->alreadyReported = TRUE;
|
||||
$this->reportData = $reportInsert;
|
||||
|
||||
/* If this is new, we need to add a data layer event */
|
||||
if ( $index->status === 1 and DataLayer::enabled( 'analytics_full' ) and static::dataLayerEventActive( 'content_report' ) )
|
||||
{
|
||||
$properties = $this->getDataLayerProperties();
|
||||
try
|
||||
{
|
||||
$reportNode = ( ( $member->member_id or !Settings::i()->automoderation_enabled ) and $reportType > 0 ) ? Types::load( $reportType ) : null;
|
||||
}
|
||||
catch ( Exception )
|
||||
{
|
||||
$reportNode = null;
|
||||
}
|
||||
|
||||
$properties['report_type_name'] = Lang::load( Lang::defaultLanguage() )->addToStack( $reportNode?->_titleLanguageKey ?: ( $this instanceof Content\Comment ? 'report_message_comment' : 'report_message_item' ) );
|
||||
$properties['report_type_id'] = $reportNode ? $reportType : 0;
|
||||
|
||||
Lang::load( Lang::defaultLanguage() )->parseOutputForDisplay( $properties['report_type_name'] );
|
||||
DataLayer::i()->addEvent( 'content_report', DataLayer::i()->filterProperties( $properties ) );
|
||||
}
|
||||
|
||||
if( $new )
|
||||
{
|
||||
Webhook::fire( 'content_reported', $index);
|
||||
|
||||
Event::fire( 'onReport', $this, [ $index ] );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $index;
|
||||
}
|
||||
@@ -2002,4 +2053,18 @@ abstract class Content extends ActiveRecord
|
||||
|
||||
return (string) $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an event is active for this content type based on the event key. For example, reports don't fire any content_* or comment_* events. This uses the $_bypassDataLayerEvents static property
|
||||
*
|
||||
* @see Content::$_bypassDataLayerEvents
|
||||
*
|
||||
* @param string $eventKey The data layer event key.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function dataLayerEventActive( string $eventKey ) : bool
|
||||
{
|
||||
return empty( static::$_bypassDataLayerEvents ) or ( is_array( static::$_bypassDataLayerEvents ) and !in_array( $eventKey, static::$_bypassDataLayerEvents ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user