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
@@ -11,16 +11,31 @@
|
||||
namespace IPS\core\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\core\Reports\Report;
|
||||
use IPS\core\Reports\Rules;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Notification;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use OutofRangeException;
|
||||
use function count;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* automaticmoderation Task
|
||||
*/
|
||||
class _automaticmoderation extends \IPS\Task
|
||||
class automaticmoderation extends Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
@@ -31,26 +46,26 @@ class _automaticmoderation extends \IPS\Task
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
* @throws Task\Exception
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : mixed
|
||||
{
|
||||
if ( ! \IPS\Settings::i()->automoderation_enabled )
|
||||
if ( ! Settings::i()->automoderation_enabled )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_automatic_moderation_pending', NULL, 'pending_added ASC', array( 0, 50 ) ) as $pending )
|
||||
foreach( Db::i()->select( '*', 'core_automatic_moderation_pending', NULL, 'pending_added ASC', array( 0, 50 ) ) as $pending )
|
||||
{
|
||||
/* Check report exists still */
|
||||
try
|
||||
{
|
||||
$report = \IPS\core\Reports\Report::load( $pending['pending_report_id'] );
|
||||
$report = Report::load( $pending['pending_report_id'] );
|
||||
}
|
||||
catch( \OutofRangeException $e )
|
||||
catch( OutofRangeException $e )
|
||||
{
|
||||
/* Report is missing */
|
||||
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_report_id=?', $pending['pending_report_id'] ) );
|
||||
Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_report_id=?', $pending['pending_report_id'] ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -61,22 +76,22 @@ class _automaticmoderation extends \IPS\Task
|
||||
{
|
||||
$object = $className::load( $pending['pending_object_id'] );
|
||||
}
|
||||
catch( \OutofRangeException $e )
|
||||
catch( OutofRangeException $e )
|
||||
{
|
||||
/* Object no longer exists */
|
||||
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $pending['pending_object_class'], $pending['pending_object_id'] ) );
|
||||
Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $pending['pending_object_class'], $pending['pending_object_id'] ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check rule exists still */
|
||||
try
|
||||
{
|
||||
$rule = \IPS\core\Reports\Rules::load( $pending['pending_rule_id'] );
|
||||
$rule = Rules::load( $pending['pending_rule_id'] );
|
||||
}
|
||||
catch( \OutofRangeException $e )
|
||||
catch( OutofRangeException $e )
|
||||
{
|
||||
/* Rule no longer exists */
|
||||
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_rule_id=?', $pending['pending_rule_id'] ) );
|
||||
Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_rule_id=?', $pending['pending_rule_id'] ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -84,30 +99,30 @@ class _automaticmoderation extends \IPS\Task
|
||||
$hidden = FALSE;
|
||||
try
|
||||
{
|
||||
if ( $object instanceof \IPS\Content\Comment )
|
||||
if ( $object instanceof Comment )
|
||||
{
|
||||
$item = $object->item();
|
||||
if ( $item and $item::$firstCommentRequired and $object->isFirst() )
|
||||
{
|
||||
/* Hide the item, not the object */
|
||||
$item->hide( FALSE, \IPS\core\Reports\Rules::getDefaultHideReason() );
|
||||
$item->hide( FALSE, Rules::getDefaultHideReason() );
|
||||
$hidden = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
|
||||
if ( $hidden === FALSE )
|
||||
{
|
||||
$object->hide( FALSE, \IPS\core\Reports\Rules::getDefaultHideReason() );
|
||||
$object->hide( FALSE, Rules::getDefaultHideReason() );
|
||||
}
|
||||
|
||||
/* Remove from the pending queue */
|
||||
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $pending['pending_object_class'], $pending['pending_object_id'] ) );
|
||||
Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $pending['pending_object_class'], $pending['pending_object_id'] ) );
|
||||
|
||||
/* Send notification to mods */
|
||||
$moderators = array( 'm' => array(), 'g' => array() );
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_moderators' ) as $mod )
|
||||
foreach ( Db::i()->select( '*', 'core_moderators' ) as $mod )
|
||||
{
|
||||
$canView = FALSE;
|
||||
if ( $mod['perms'] == '*' )
|
||||
@@ -131,16 +146,16 @@ class _automaticmoderation extends \IPS\Task
|
||||
|
||||
try
|
||||
{
|
||||
$latestReport = \IPS\Db::i()->select( '*', 'core_rc_reports', array( 'rid=?', $report->id ), 'date_reported DESC' )->first();
|
||||
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'automatic_moderation', $report, array( $report, $latestReport, $object ) );
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_members', ( \count( $moderators['m'] ) ? \IPS\Db::i()->in( 'member_id', $moderators['m'] ) . ' OR ' : '' ) . \IPS\Db::i()->in( 'member_group_id', $moderators['g'] ) . ' OR ' . \IPS\Db::i()->findInSet( 'mgroup_others', $moderators['g'] ) ) as $member )
|
||||
$latestReport = Db::i()->select( '*', 'core_rc_reports', array( 'rid=?', $report->id ), 'date_reported DESC' )->first();
|
||||
$notification = new Notification( Application::load('core'), 'automatic_moderation', $report, array( $report, $latestReport, $object ) );
|
||||
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 $member )
|
||||
{
|
||||
$notification->recipients->attach( \IPS\Member::constructFromData( $member ) );
|
||||
$notification->recipients->attach( Member::constructFromData( $member ) );
|
||||
}
|
||||
|
||||
$notification->send();
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in new issue
Block a user